Calling OpenSSL_thread_stop() multiple times

Matt Caswell matt at
Wed Aug 23 13:31:46 UTC 2023

On 23/08/2023 10:54, Dipak B wrote:
> 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) ?

So, IIUC, TalkToWeb is a function called by a single thread and each 
thread calls it once and then the thread exits. Is that correct?

In which case calling OPENSSL_thread_stop() at the end of TalkToWeb() 
would be a good solution.

> 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().

Right. You cannot re-use the same thread after calling 
OPENSSL_thread_stop(). If you wan to re-use the thread then you must 
rearrange things such that OPENSSL_thread_stop() is only called after 
the *last* time that it is reused.


> Please let me know if any specific part is unclear I will try to 
> describe it.
> Thanks and Regards

More information about the openssl-users mailing list