Hello fellow developers:

I have been trying to track down a memory leak in my spop3 client
and have narrowed it down to the following KISS code:

BTW: OpenSSL Version 0.9.5.a with MS VC++ 6.0 SP4
==================================================
// KISS-test

// Initialize OpenSSL
  SSL_library_init();
  RAND_screen();
  SSL_load_error_strings();

  // The next  lines leak
    SSL_CTX * m_ctx = SSL_CTX_new (SSLv2_client_method());
    _ASSERT(m_ctx);
    SSL_CTX_free (m_ctx);

// Cleanup OpenSSL
 ERR_remove_state(0);
 EVP_cleanup();
 ERR_free_strings();

======================================================
Detected memory leaks!
Dumping objects ->
{1407} normal block at 0x00A768E0, 20 bytes long.
 Data: <     WM         > 00 00 00 00 A8 57 4D 00 00 00 00 00 00 00 00 00
{1406} normal block at 0x00A76920, 16 bytes long.
 Data: < h              > E0 68 A7 00 00 00 00 00 00 00 00 00 00 00 00 00
{1405} normal block at 0x00A76960, 20 bytes long.
 Data: <     i          > 01 00 00 00 20 69 A7 00 00 00 00 00 04 00 00 00
Object dump complete.
=======================================================

If I remove the calls to SSL_CTX_new() and SSL_CTX_free() the leak
disappeers. Putting the 2 lines in a loop and calling it, say, 10 times,
doesn't increase the leak.

I traced into the code to exactly locate where the memory leaks are
initially allocated:

1st memory leak:

CRYPTO_malloc(int 20, const char * 0x004cf9c8, int 117) line 208
sk_new(int (void)* 0x00000000) line 117 + 14 bytes
sk_CRYPTO_EX_DATA_FUNCS_new_null() line 223 + 10 bytes
CRYPTO_get_ex_new_index(int 0, stack_st_CRYPTO_EX_DATA_FUNCS * * 0x004e7b44
x509_store_ctx_method, long 0, void * 0x004d57a8, int (void *, void *,
crypto_ex_data_st *, int, long, void *)* 0x00000000, int (crypto_ex_data_st
*, crypto_ex_data_st *, void *, int, long, void *)* 0x00000000, void (void
*, void *, crypto_ex_data_st *, int, long, void *)* 0x00000000) line 74 + 5
bytes
X509_STORE_CTX_get_ex_new_index(long 0, void * 0x004d57a8, int (void *, void
*, crypto_ex_data_st *, int, long, void *)* 0x00000000, int
(crypto_ex_data_st *, crypto_ex_data_st *, void *, int, long, void *)*
0x00000000, void (void *, void *, crypto_ex_data_st *, int, long, void *)*
0x00000000) line 685 + 39 bytes
SSL_get_ex_data_X509_STORE_CTX_idx() line 137 + 18 bytes
SSL_CTX_new(ssl_method_st * 0x004e7c70 SSLv2_client_data) line 1097 + 5
bytes

2nd memory leak:
CRYPTO_malloc(int 16, const char * 0x004cf9e0, int 119) line 208
sk_new(int (void)* 0x00000000) line 119 + 14 bytes
sk_CRYPTO_EX_DATA_FUNCS_new_null() line 223 + 10 bytes
CRYPTO_get_ex_new_index(int 0, stack_st_CRYPTO_EX_DATA_FUNCS * * 0x004e7b44
x509_store_ctx_method, long 0, void * 0x004d57a8, int (void *, void *,
crypto_ex_data_st *, int, long, void *)* 0x00000000, int (crypto_ex_data_st
*, crypto_ex_data_st *, void *, int, long, void *)* 0x00000000, void (void
*, void *, crypto_ex_data_st *, int, long, void *)* 0x00000000) line 74 + 5
bytes
X509_STORE_CTX_get_ex_new_index(long 0, void * 0x004d57a8, int (void *, void
*, crypto_ex_data_st *, int, long, void *)* 0x00000000, int
(crypto_ex_data_st *, crypto_ex_data_st *, void *, int, long, void *)*
0x00000000, void (void *, void *, crypto_ex_data_st *, int, long, void *)*
0x00000000) line 685 + 39 bytes
SSL_get_ex_data_X509_STORE_CTX_idx() line 137 + 18 bytes
SSL_CTX_new(ssl_method_st * 0x004e7c70 SSLv2_client_data) line 1097 + 5
bytes

3rd memory leak:
CRYPTO_malloc(int 20, const char * 0x004cebf8, int 80) line 208
CRYPTO_get_ex_new_index(int 0, stack_st_CRYPTO_EX_DATA_FUNCS * * 0x004e7b44
x509_store_ctx_method, long 0, void * 0x004d57a8, int (void *, void *,
crypto_ex_data_st *, int, long, void *)* 0x00000000, int (crypto_ex_data_st
*, crypto_ex_data_st *, void *, int, long, void *)* 0x00000000, void (void
*, void *, crypto_ex_data_st *, int, long, void *)* 0x00000000) line 80 + 14
bytes
X509_STORE_CTX_get_ex_new_index(long 0, void * 0x004d57a8, int (void *, void
*, crypto_ex_data_st *, int, long, void *)* 0x00000000, int
(crypto_ex_data_st *, crypto_ex_data_st *, void *, int, long, void *)*
0x00000000, void (void *, void *, crypto_ex_data_st *, int, long, void *)*
0x00000000) line 685 + 39 bytes
SSL_get_ex_data_X509_STORE_CTX_idx() line 137 + 18 bytes
SSL_CTX_new(ssl_method_st * 0x004e7c70 SSLv2_client_data) line 1097 + 5
bytes

So, a single call to CRYPTO_get_ex_new_index() allocated these memory blocks
and nothing frees them.
Am I missing something?

tia,
  Martin


______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to