On Tue, Jan 28, 2014, at 01:41 PM, Dr. Stephen Henson wrote:
> 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.
> --
> Dr Stephen N. Henson. OpenSSL project core developer.
> Commercial tech support now available see: http://www.openssl.org

Thanks for the clarification Steve. If I'm understanding this correctly,
then the pattern should be something like this:

do
{
  rc = ERR_get_error_line_data()
  if rc == 0 break
} while true
ERR_clear_error() // to free the memory that may have been allocated in
the error queue

Does this make sense? Is the extra call to ERR_clear_error() necessary
to clean up?

Thanks,
Adam
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to