[openssl-users] Handle Leaks - shmem-win32.c shmem.c - OpenSSL 1.0.1l

Michel SALES michel.sales at OnLine.fr
Sun Jan 25 11:05:48 UTC 2015


Hi Avery,

I am afraid your program demonstrates very little.

If you load OpenSSL library, you have to call some of the OpenSSL free
functions as indicated in a previous post,
and if you create a thread, you have to call CloseHandle() :

#include <windows.h>
#include <crtdbg.h>

#include <openssl/ssl.h>
#include <openssl/err.h>

DWORD __stdcall thread1( LPVOID l )
{
    for( int i=0; i<7; i++ ) 
        Sleep(1000);
    ERR_remove_state(0);
    return 0;
}

int main( int argc, char* argv[] )
{
//  _crtBreakAlloc = ...;

    SSL_library_init();
    SSL_load_error_strings();

    DWORD  t1;
    HANDLE h1 = CreateThread( 0, 0, thread1, 0, 0, &t1 );

    for( int i=0; i<7; i++ ) Sleep(1000);

    if( h1 ) { 
        WaitForSingleObject( thread1, INFINITE );
        CloseHandle( h1 );
    }
    
    ERR_remove_state(0);
    EVP_cleanup();
    ERR_free_strings();
    CRYPTO_cleanup_all_ex_data();
    sk_SSL_COMP_free( SSL_COMP_get_compression_methods());

    _CrtDumpMemoryLeaks();

    return 0;
}

Hope it helps,

Michel


De : openssl-users [mailto:openssl-users-bounces at openssl.org] De la part de
Avery A. Tarasov
Envoyé : samedi 24 janvier 2015 22:34
À : openssl-users at openssl.org
Objet : Re: [openssl-users] Handle Leaks - shmem-win32.c shmem.c - OpenSSL
1.0.1l

Hi Michel,

It doesn't appear to be related to that.  I added CloseHandle's and got the
same result.

Here are my updated findings... The following simple program still causes
the same Handle Leaks...

Important findings:

1)  If    SSL_library_init() and SSL_load_error_strings() are removed (which
are the only 2 OpenSSL functions I'm using).... the handle leaks go away.. 
2)  If    SSL_library_init() and SSL_load_error_strings() are kept but the
creation of the thread is removed  -- no more handle leaks..

So the problem is something related to the combination of loading OpenSSL
and creating a thread (even though that thread does nothing whatsoever
related to OpenSSL).  Very odd.

DWORD __stdcall thread1(LPVOID l)
{
    while(1)
    {   Sleep(1000);    }
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
lpCmdLine, int nCmdShow) {


     SSL_library_init();   // if these 2 lines removed
    SSL_load_error_strings();  // no more handle leaks
    DWORD t1;
    
    HANDLE h1=CreateThread(0,0,thread1,0,0,&t1);  if(h1==0)  {  return
0;     }      CloseHandle(h1);  //if  SSL_library_init(); and
SSL_load_error_strings();  are kept  but this line is removed... no more
handle leaks


    while(1)
    {
        Sleep(1000);
    }
}






More information about the openssl-users mailing list