<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 12 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:#333333;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"Préformaté HTML Car";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.apple-converted-space
        {mso-style-name:apple-converted-space;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.PrformatHTMLCar
        {mso-style-name:"Préformaté HTML Car";
        mso-style-priority:99;
        mso-style-link:"Préformaté HTML";
        font-family:"Courier New";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body bgcolor=white lang=FR link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>1)  Am I correct that I only need to call the SSL_library_init(); and SSL_load_error_strings();  once at the beginning of the program , and not at the beginning of each thread?<br><br><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Yes<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal>2)  Should I be doing any other cleanup functions within the threads?<br><br><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p></o:p></span></p><pre><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Yes, </span>ERR_remove_state()<o:p></o:p></pre><p class=MsoNormal><br>Should I be doing any other cleanup operations ?<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Probably some of (before exiting main thread only) :<o:p></o:p></p><p class=MsoNormal>    EVP_cleanup();<o:p></o:p></p><p class=MsoNormal>    ERR_free_strings();<o:p></o:p></p><p class=MsoNormal>    CRYPTO_cleanup_all_ex_data();<o:p></o:p></p><p class=MsoNormal>    ENGINE_cleanup();<o:p></o:p></p><p class=MsoNormal>    CONF_modules_unload( 1 );<o:p></o:p></p><p class=MsoNormal>    CONF_modules_free();<o:p></o:p></p><p class=MsoNormal>    sk_SSL_COMP_free( SSL_COMP_get_compression_methods());<o:p></o:p></p><p class=MsoNormal>    RAND_cleanup();    <o:p></o:p></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal>Hope it helps,<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Michel.<span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'>De :</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'> openssl-users [mailto:openssl-users-bounces@openssl.org] <b>De la part de</b> Avery A. Tarasov<br><b>Envoyé :</b> jeudi 22 janvier 2015 06:36<br><b>À :</b> openssl-users@openssl.org<br><b>Objet :</b> [openssl-users] Proper cleanup functions being called?<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Hi All,<br><br>I am using OpenSSL 1.0.1l   in Win32 environment.  At the beginning of my program I call<br><br>    SSL_library_init();<br>    SSL_load_error_strings();<br><br>Those functions are only called once.<br><br>Then I have 3 threads which can't possibly be run at the same time due to mutexes I'm setting with WaitForSingleObject and ReleaseMutex.  Those 3 threads use these functions below and all variables in those threads are local to the threads (e.g. no globals).<br><br>SSL_CTX_new<br>SSL_CTX_set_verify<br>SSL_CTX_set_cert_verify_callback<br>BIO_new_connect<br>BIO_do_connect<br>SSL_new<br>SSL_set_bio<br>SSL_get_peer_certificate<br>SSL_write<br>SSL_read<br>SSL_get_error<br><br><br>(cleanup functions.. if conditions used to prevent double frees, etc.)<br>X509_free<br>SSL_shutdown<br>SSL_free<br>BIO_free<br>SSL_CTX_free<br><br><br><br><br>My questions are the following:<br><br>1)  Am I correct that I only need to call the SSL_library_init(); and SSL_load_error_strings();  once at the beginning of the program , and not at the beginning of each thread?<br>2)  Should I be doing any other cleanup functions within the threads?<br><br>My program appears to work perfectly but a tool is complaining about memory leaks in _CRYPTO_malloc, _asn1_enc_save,  _asn1_item_ex_d2i, _d2i_X509<br><br>Handle leaks<br><br>_shmem_winpthreads_grab<br>_pthread_register_pointer<br><br>In fact I get memory leaks reported if I just do    SSL_library_init(); alone<br><br>Despite the reports of the leaks my program seems to run fine for days and stay consistent in memory used.  But I'm feeling paranoid something just isn't quite right.<br><br>Should I be doing any other cleanup operations?<br><br>Thanks for the assistance.<br><br>Best Regards,<br><br>-Avery T.<o:p></o:p></p></div></body></html>