[openssl-dev] memory leaks detected using libSSL 1.1

Matt Caswell matt at openssl.org
Thu Feb 18 10:17:45 UTC 2016



On 18/02/16 00:13, Michel wrote:
> Hi Matt, 
> 
> Thanks for the suggestion.
> 
> This is what was printed to stderr :
> OPENSSL_INIT: ossl_init_base: Setting up stop handlers
> OPENSSL_INIT: ossl_init_add_all_ciphers: openssl_add_all_ciphers_internal()
> OPENSSL_INIT: ossl_init_add_all_digests: openssl_add_all_digests_internal()
> OPENSSL_INIT: ossl_init_ssl_base: Adding SSL ciphers and digests
> OPENSSL_INIT: ossl_init_ssl_base: SSL_COMP_get_compression_methods()
> OPENSSL_INIT: ossl_init_ssl_base: SSL_add_ssl_module()
> OPENSSL_INIT: ossl_init_load_ssl_strings: ERR_load_SSL_strings()
> OPENSSL_INIT: ossl_init_async: async_init()
> OPENSSL_INIT: ossl_init_load_crypto_strings:
> err_load_crypto_strings_intern()
> OPENSSL_INIT: ossl_init_thread_start: marking thread for err_state
> OPENSSL_INIT: ossl_init_thread_start: marking thread for err_state
> OPENSSL_INIT: ossl_init_thread_stop: ERR_remove_thread_state(NULL)
> OPENSSL_INIT: ssl_library_stop: SSL_COMP_free_compression_methods()
> OPENSSL_INIT: ssl_library_stop: ERR_free_strings()
> OPENSSL_INIT: OPENSSL_cleanup: ERR_free_strings()
> OPENSSL_INIT: OPENSSL_INIT_library_stop: CRYPTO_cleanup_all_ex_data()
> OPENSSL_INIT: OPENSSL_INIT_library_stop: EVP_cleanup()
> OPENSSL_INIT: OPENSSL_INIT_library_stop: CONF_modules_free()
> OPENSSL_INIT: OPENSSL_INIT_library_stop: RAND_cleanup()
> 
> Shouldn't there be at least another line with ERR_remove_thread_state() (one
> for each thread) ?

Yes. I can see we have two of these:

OPENSSL_INIT: ossl_init_thread_start: marking thread for err_state
OPENSSL_INIT: ossl_init_thread_start: marking thread for err_state

Which means that the init code has spotted that there are two threads
running and has initialised the error system for both of them.

But we only get one of these:

OPENSSL_INIT: ossl_init_thread_stop: ERR_remove_thread_state(NULL)

Which means only one of the two threads has subsequently been de-inited.
That's very odd.

I have two possible theories:
1) OPENSSL_thread_stop() is not actually getting called as we think it is.
Or
2) The Thread Local Structure that keeps track of what things need
cleanup is not being obtained correctly for some reason during the
thread stop...so we have "forgotten" that we initialised the error system.

To try and help narrow down which of these possibilities it is I have
created a patch (attached) which bumps up the logging significantly.
Please can you apply it, rerun your code (with OPENSSL_INIT_DEBUG
defined still) and post the output here?

Thanks

Matt


> This test program launch 1 server thread and 1 client thread.
> Both of them have OPENSSL_thread_stop() in their [pre-]exit member function.
> 
> Michel.
> 
> -----Message d'origine-----
> De : openssl-dev [mailto:openssl-dev-bounces at openssl.org] De la part de Matt
> Caswell
> Envoyé : mercredi 17 février 2016 17:23
> À : openssl-dev at openssl.org
> Objet : Re: [openssl-dev] memory leaks detected using libSSL 1.1
> 
>> Am I missing anything else ?
> 
> That should be sufficient (although the OPENSSL_cleanup() should not be
> required).
> 
> You could try compiling OpenSSL with OPENSSL_INIT_DEBUG defined, e.g.
> 
> perl Configure your-platform-here -DOPENSSL_INIT_DEBUG
> 
> This should print out some debugging information to stderr every time the
> init functions attempt to do something interesting. In particular when you
> call OPENSSL_thread_stop() you should see the following printed
> out:
> 
> OPENSSL_INIT: ossl_init_thread_stop: ERR_remove_thread_state(NULL)
> 
> Matt
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: thread-stop-debug.patch
Type: text/x-patch
Size: 5301 bytes
Desc: not available
URL: <http://mta.openssl.org/pipermail/openssl-dev/attachments/20160218/6dbc8873/attachment.bin>


More information about the openssl-dev mailing list