> From: Dr. Stephen Henson [mailto:st...@openssl.org]
> Sent: Tuesday, January 28, 2014 6:41 PM
> On Tue, Jan 28, 2014, Adam M wrote:
> 
> > Hi,
> >
> > 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.com/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?
> >
> 
> You can see and example of how it is used internally in the library in
> crypto/err/err_prn.c all you need to check is that ERR_TXT_STRING is
> set. The
> flag ERR_TXT_MALLOCED is an internal flag which indicates whether the
> string
> should be freed when the error queue is emptied: applications must not
> free the
> string themselves.
> 
> Steve.

Surely ERR_get_error_line_data() passes ownership of the data to the caller, 
and removes it from the error queue? How would the library know to free it 
subsequently? I remember analyzing the source in some detail a while ago when I 
was wondering the same as Adam, and that's the conclusion I came to at least.
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to