I suspect this will result in a double free bug, as I don't think memory ownership of 'data' is actually passed back to the caller (which is why it's 'const char**'). The error isn't really 'popped' from the queue - the queue just gets some indexes adjusted but the structure itself seems unmodified by ERR_get_error_line_data(). What is still moderately unclear is exactly at what point the OpenSSL library goes in and cleans out the error queue. My guess (as I said in my previous email) is that the user should call ERR_clear_error() when the error queue becomes empty, to actually go through and clean out the internal structures. I'll let the OpenSSL experts clarify that, however. In any case, the documentation could definitely be improved in this regard.
-Adam On Tue, Jan 28, 2014, at 01:33 PM, Jeremy Farrell wrote: > In C: > > if ( data != NULL && flags & ERR_TXT_STRING ) { > > PRINT(data); > > if ( flags & ERR_TXT_MALLOCED ) { > OPENSSL_free((void *)data); > } > } > > > From: Adam M [mailto:open...@irotas.net] > > Sent: Tuesday, January 28, 2014 5:47 PM > > To: openssl-users@openssl.org > > > > I'm reading the documentation for ERR_get_error_line_data() here: > > http://www.openssl.org/docs/crypto/ERR_get_error.html > > > > The comments say that 'data' is dynamically allocated with > > OPENSSL_malloc() if the ERR_TXT_MALLOCED bit is set in 'flags'. I > > presume this means that we need to call OPENSSL_free() to free 'data', > > but the documentation isn't clear on that. > > > > I'm running into two issues in this regard. For one, 'data' is a 'const > > char*', but OPENSSL_free() takes a 'void*', so we get a type mismatch. > > See my sample code here, which includes the compiler error message: > > http://pastebin.ct om/VNdkwf0G > > > > The second issue is that I've been looking around on the web (in > > particular on Ohloh) for usage of ERR_get_error_line_data(), and no one > > seems to be checking for the ERR_TXT_MALLOCED bit in 'flags'. Maybe > > doing so isn't necessary, but the documentation seems to suggest that > > it > > is. > > > > Can someone please help clarify what exactly to do here? > > > > Thanks, > > Adam > ______________________________________________________________________ > OpenSSL Project http://www.openssl.org > User Support Mailing List openssl-users@openssl.org > Automated List Manager majord...@openssl.org ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager majord...@openssl.org