Re: Calling OpenSSL_thread_stop() multiple times

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On Wed, Aug 23, 2023, 3:03 PM Matt Caswell <matt@xxxxxxxxxxx> 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 

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux