Calling OpenSSL_thread_stop() multiple times
Dipak B
deepak.redmi2 at gmail.com
Wed Aug 23 09:54:48 UTC 2023
On Wed, Aug 23, 2023, 3:03 PM Matt Caswell <matt at openssl.org> wrote:
>
>
> On 22/08/2023 19:40, Dipak B wrote:
> > Not calling Openssl_stop_thread() leads to memory leaks inside
> > ERR_get_error() for me.
> > _malloc_base+0x44
> > CRYPTO_zalloc+0x54
> > ossl_err_get_state_int+0x9E
> > ERR_clear_error+0x14
> > ossl_send+0x45
> > ssl_cf_send+0x36
> > Curl_write+0x3C
> > Curl_buffer_send+0x11B
> > Curl_http_bodysend+0x706
> > Curl_http+0xAAA
> > multi_runsingle+0x7F4
> > curl_multi_perform+0x80
> > curl_easy_perform+0x137
> >
> > So, can following be supported?
> >
> > Communicate.DLL statically linked to ossl 3.x & libcurl 8.x exporting 3
> > functions
> >
> > Initialize()
> > {
> > SSL_library_init(); or openssl_int_ssl(load no err strings)
> >
> > curl_global_init();
> >
> > curl_easy_init(); // multiple times generating curl handles to be stored
> > in array of say 16
> > }
> >
> > Shutdown
> > {
> > curl_easy_cleanup(); // multiples times for each handle inside array
> >
> > Openssl_stop_thread(); // once for each curl handle; so 16 times
> >
> > curl_global_cleanup();
> > }
> >
> > TalkToWeb
> > {
> > setup_curl_options();
> > curl_easy_perform();
> >
> > // openssl_stop_thread(); // having this here solves the memory leak
> for me
> > }
> >
> > TalkToWeb() is called by new threads (each invocation is with new
> > thread) created by an executable which loads communicate.DLL
> >
> > Execution of above code leads to accumulation of memory until Shutdown()
> > is called.
> >
> > Libcurl encourages handle re-use.
> >
>
> I'm not really clear what your asking here. OPENSSL_thread_stop() must
> only be called once per thread, and you cannot use OpenSSL on that
> thread after that point. As long as you obey those rules then you should
> be fine.
>
> Matt
>
Need input on following questions.
In the application with pseudo code as above, not using
Openssl_stop_thread() inside function TalkToWeb() leads to memory leak
which gets accumulated until function Shutdown() is called.
How can I avoid memory leak (stack shared above) ?
Can I deduct the following conclusion?
There is constraint on an application (exe) using a DLL which is statically
linked to ossl. This constraint is due to openssl.
Constraint:
If thread originating in such a application calls function TalkToWeb()
above then it has to call openssl_stop_thread() inside TalkToWeb().
This does not allow one to re-use same thread for calling TalkToWeb().
Please let me know if any specific part is unclear I will try to describe
it.
Thanks and Regards
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mta.openssl.org/pipermail/openssl-users/attachments/20230823/469f1cb0/attachment-0001.htm>
More information about the openssl-users
mailing list