<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#333333">
<div class="moz-cite-prefix">Hi Michel,<br>
<br>
In the code I sent over before, I was calling CloseHandle on the
thread:<br>
<br>
<pre wrap="">HANDLE h1=CreateThread(0,0,thread1,0,0,&t1); if(h1==0) { return 0; } <b>CloseHandle(h1); </b> </pre>
<br>
I modified the code you sent slightly so the cleanup functions
all get reached. Still getting handle leaks (see info at bottom
of the email thread). In the code below, I check the program for
leaks once the MessageBox pops up after all the cleanup
functions. Then there is a 20 second pause after which the
program exits.<br>
<br>
The results are the same as before.. why is it that the program
doesn't leak anymore if the creation of the thread is removed
which essentially does nothing? Also why is it that if all the
SSL functions are removed in the program, but the thread is still
created the leaks go away? Something weird is going on. It is as
if OpenSSL just doesn't like the CreateThread function being used
(even if the thread doesn't do anything related to OpenSSL (tried
modifying code in the thread to do nothing -- e.g. blank thread).
Thanks for the help, all.<br>
<br>
for( int i=0; i<7; i++ ) Sleep(1000);<br>
<br>
CloseHandle( h1 );<br>
<br>
ERR_remove_state(0);<br>
EVP_cleanup();<br>
ERR_free_strings();<br>
CRYPTO_cleanup_all_ex_data();<br>
sk_SSL_COMP_free( SSL_COMP_get_compression_methods());<br>
<br>
_CrtDumpMemoryLeaks();<br>
<br>
<b>MessageBox</b>(0,"gothere","gothere",0); <b>// at this
point Handle leaks are still being reported... see data below</b><br>
<br>
Sleep(20000);<br>
<br>
<br>
<br>
<br>
Address / Handle: 0x0000C001<br>
shmem-win32.c<br>
sslleak.exe <br>
Atom<br>
0 bytes<br>
Thread ID: 14524<br>
1/25 11:38:34 827ms (Lifetime:00:00:39:561ms)<br>
Sequence: 11<br>
sslleak.exe ___shmem_grab : [shmem-win32.c Line 0]<br>
sslleak.exe _fc_key_init_once : [unwind-sjlj.c Line 0]<br>
sslleak.exe ___tmainCRTStartup : [crtexe.c Line 0]<br>
kernel32.dll BaseThreadInitThunk : [{FUNC}BaseThreadInitThunk
Line 0]<br>
ntdll.dll RtlInitializeExceptionChain :
[{FUNC}RtlInitializeExceptionChain Line 0]<br>
ntdll.dll RtlInitializeExceptionChain :
[{FUNC}RtlInitializeExceptionChain Line 0]<br>
<br>
<br>
<br>
Address / Handle: 0x0000C004<br>
shmem.c<br>
sslleak.exe <br>
Atom<br>
0 bytes<br>
Thread ID: 14524<br>
1/25 11:38:34 827ms (Lifetime:00:00:39:561ms)<br>
Sequence: 27<br>
sslleak.exe ___shmem_winpthreads_grab : [shmem.c Line 0]<br>
sslleak.exe _mutex_ref_init : [mutex.c Line 0]<br>
sslleak.exe _enterOnceObject : [thread.c Line 0]<br>
sslleak.exe ___tmainCRTStartup : [crtexe.c Line 0]<br>
kernel32.dll BaseThreadInitThunk : [{FUNC}BaseThreadInitThunk
Line 0]<br>
ntdll.dll RtlInitializeExceptionChain :
[{FUNC}RtlInitializeExceptionChain Line 0]<br>
<br>
Address / Handle: 0x0000C00F<br>
shmem-win32.c<br>
sslleak.exe <br>
Atom<br>
0 bytes<br>
Thread ID: 14524<br>
1/25 11:38:34 827ms (Lifetime:00:00:39:561ms)<br>
Sequence: 97<br>
sslleak.exe ___shmem_grab : [shmem-win32.c Line 0]<br>
sslleak.exe ___shmem_grab : [shmem-win32.c Line 0]<br>
<br>
Address / Handle: 0x0000C009<br>
shmem.c<br>
sslleak.exe <br>
Atom<br>
0 bytes<br>
Thread ID: 14524<br>
1/25 11:38:34 827ms (Lifetime:00:00:39:561ms)<br>
Sequence: 61<br>
sslleak.exe ___shmem_winpthreads_grab : [shmem.c Line 0]<br>
sslleak.exe _mutex_static_init : [mutex.c Line 0]<br>
sslleak.exe _pop_pthread_mem : [thread.c Line 0]<br>
sslleak.exe _pop_pthread_mem : [thread.c Line 0]<br>
<br>
<br>
<br>
Address / Handle: 0x0000C012<br>
shmem.c<br>
sslleak.exe <br>
Atom<br>
0 bytes<br>
Thread ID: 14524<br>
1/25 11:38:34 842ms (Lifetime:00:00:39:546ms)<br>
Sequence: 112<br>
sslleak.exe ___shmem_winpthreads_grab : [shmem.c Line 0]<br>
sslleak.exe _rwlock_static_init : [rwlock.c Line 0]<br>
sslleak.exe _rwlock_static_init : [rwlock.c Line 0]<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
On 1/25/2015 6:05 AM, Michel SALES wrote:<br>
</div>
<blockquote
cite="mid:000601d0388e$e06bff70$a143fe50$@sales@OnLine.fr"
type="cite">
<pre wrap="">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 [<a class="moz-txt-link-freetext" href="mailto:openssl-users-bounces@openssl.org">mailto:openssl-users-bounces@openssl.org</a>] De la part de
Avery A. Tarasov
Envoyé : samedi 24 janvier 2015 22:34
À : <a class="moz-txt-link-abbreviated" href="mailto:openssl-users@openssl.org">openssl-users@openssl.org</a>
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);
}
}
_______________________________________________
openssl-users mailing list
To unsubscribe: <a class="moz-txt-link-freetext" href="https://mta.openssl.org/mailman/listinfo/openssl-users">https://mta.openssl.org/mailman/listinfo/openssl-users</a>
</pre>
</blockquote>
<br>
</body>
</html>