<div dir="auto">Do you have a moment to edit or review my error <br><br><div data-smartmail="gmail_signature">Ryan Murray</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Jan 6, 2017 10:55 AM, "Matt Caswell" <<a href="mailto:matt@openssl.org">matt@openssl.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
On 06/01/17 14:36, Dan Heinz wrote:<br>
>>> On 04/01/17 23:11, Dan Heinz wrote: Using openssl 1.1.0c.<br>
>>><br>
>>> I have a test application that is a win32 console app that calls<br>
>>> a win32 DLL which has the openssl libraries linked in<br>
>>> statically.<br>
>>><br>
>>> The test applications uses late-binding to the DLL and calls<br>
>>> LoadLibrary for the DLL, one test function in the DLL, and then<br>
>>> FreeLibrary on the DLL.<br>
>>><br>
>>><br>
>>><br>
>>> The test function in the DLL does the following:<br>
>>><br>
>>> RSA*rsa = NULL;<br>
>>><br>
>>> rsa = RSA_new();<br>
>>><br>
>>> RSA_free(rsa);<br>
>>><br>
>>> OPENSSL_thread_stop();<br>
>>><br>
>>> OPENSSL_cleanup();<br>
>>><br>
>>> return0;<br>
>>><br>
>>> When FreeLibrary is called on the DLL, dllmain in never called<br>
>>> with any messages.  A subsequent call to LoadLibrary also fails<br>
>>> to call dllmain and when the test function is called RSA_new()<br>
>>> fails.  This leads me to believe the DLL is never freed.<br>
>>><br>
>>> I have tried building openssl with and without no-threads with<br>
>>> the same results.  My build parameters are: perl Configure<br>
>>> *%TEMP_ARCHITECTURE%*<br>
>>> --prefix=*%RootPath_<wbr>ThirdParty%*\*%OPENSSL_<wbr>VERSION%* -DPURIFY<br>
>>> -DOPENSSL_NO_COMP -D_USING_V110_SDK71_ no-shared no-threads<br>
>>> no-asm no-idea no-mdc2 no-rc5  no-ssl3 no-zlib no-comp<br>
>>><br>
>>> What am I missing?<br>
>><br>
>><br>
>> OpenSSL does its cleanup at *process* exit. Don't call<br>
>> OPENSSL_cleanup() explicitly - this is >discouraged.<br>
>><br>
>> From this manpage:<br>
>><br>
>> <a href="https://www.openssl.org/docs/man1.1.0/crypto/OPENSSL_init_crypto.html" rel="noreferrer" target="_blank">https://www.openssl.org/docs/<wbr>man1.1.0/crypto/OPENSSL_init_<wbr>crypto.html</a><br>
>><br>
>><br>
>><br>
"Typically there should be no need to call this function directly as it<br>
is initiated >automatically on application exit...<snip>...<br>
>><br>
>> Once OPENSSL_cleanup() has been called the library cannot be<br>
>> reinitialised."<br>
>><br>
>> This last sentence is the reason why RSA_new() will fail after you<br>
>> have previously called >OPENSSL_cleanup().<br>
>><br>
>> Because cleanup happens on process exit, OpenSSL will keep itself<br>
>> in memory until that time >(otherwise crashes will occur because<br>
>> the cleanup routines have been unloaded).<br>
>><br>
>> If you want to dynamically load and unload your DLL then don't<br>
>> statically link it to OpenSSL - >otherwise OpenSSL will keep your<br>
>> DLL around until process exit too.<br>
>><br>
>> Matt<br>
><br>
> That is very disappointing.  As a library vendor we have no control<br>
> over how our users load and unload our libraries.  We will just have<br>
> to roll back to 1.0.x and wait to see if this will be addressed.<br>
> Also, as Jakob stated in another post, it really seems like this<br>
> design will be problematic.<br>
<br>
Can you not link against the OpenSSL DLLs rather than statically link?<br>
That would avoid the problem.<br>
<br>
Matt<br>
<br>
<br>
--<br>
openssl-users mailing list<br>
To unsubscribe: <a href="https://mta.openssl.org/mailman/listinfo/openssl-users" rel="noreferrer" target="_blank">https://mta.openssl.org/<wbr>mailman/listinfo/openssl-users</a><br>
</blockquote></div></div>