Memory leaks...

View: New views
2 Messages — Rating Filter:   Alert me  

Memory leaks...

by barcaroller :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I'm getting some memory leaks when I use OpenSSL.  I was not able to get rid
of these leaks, even when I use EVP_cleanup() and ERR_free_strings() at the
end of my program.


Memory Leak 1.  PEM_read_PrivateKey()
=====================================

    EVP_PKEY* key = PEM_read_PrivateKey(fp, NULL, 0, NULL);
        ...
    EVP_PKEY_free(key);

    Valgrind reports:

    ==27769== 24 bytes in 1 blocks are still reachable in loss record 2 of
20
    ==27769==    at 0x4A05809: malloc (vg_replace_malloc.c:149)
    ==27769==    by 0x3C3C6DAD41: CRYPTO_malloc (in
/lib64/libcrypto.so.0.9.8e)
    ==27769==    by 0x3C3C65B565: (within /lib64/libcrypto.so.0.9.8e)
    ==27769==    by 0x3C3C65B98A: (within /lib64/libcrypto.so.0.9.8e)
    ==27769==    by 0x3C3C66F9B3: RSA_new_method (in
/lib64/libcrypto.so.0.9.8e)
    ==27769==    by 0x3C3C66F33C: (within /lib64/libcrypto.so.0.9.8e)
    ==27769==    by 0x3C3C692EA4: (within /lib64/libcrypto.so.0.9.8e)
    ==27769==    by 0x3C3C696004: ASN1_item_ex_d2i (in
/lib64/libcrypto.so.0.9.8e)
    ==27769==    by 0x3C3C6960F3: ASN1_item_d2i (in
/lib64/libcrypto.so.0.9.8e)
    ==27769==    by 0x3C3C68FC0C: d2i_PrivateKey (in
/lib64/libcrypto.so.0.9.8e)
    ==27769==    by 0x3C3C6A10B9: PEM_read_bio_PrivateKey (in
/lib64/libcrypto.so.0.9.8e)
    ==27769==    by 0x3C3C6A1300: PEM_read_PrivateKey (in
/lib64/libcrypto.so.0.9.8e)


Memory Leak 2. SSL_library_init()
=================================

    Valgrind reports:

    ==27769== 24 bytes in 1 blocks are still reachable in loss record 6 of
20
    ==27769==    at 0x4A05809: malloc (vg_replace_malloc.c:149)
    ==27769==    by 0x3C3C6DAD41: CRYPTO_malloc (in
/lib64/libcrypto.so.0.9.8e)
    ==27769==    by 0x3C3C65B565: (within /lib64/libcrypto.so.0.9.8e)
    ==27769==    by 0x3C3C65BB3B: (within /lib64/libcrypto.so.0.9.8e)
    ==27769==    by 0x3C3C6BFBFA: COMP_zlib (in /lib64/libcrypto.so.0.9.8e)
    ==27769==    by 0x3C3CA31D7F: (within /lib64/libssl.so.0.9.8e)
    ==27769==    by 0x3C3CA31F48: SSL_COMP_get_compression_methods (in
/lib64/libssl.so.0.9.8e)
    ==27769==    by 0x3C3CA37784: SSL_library_init (in
/lib64/libssl.so.0.9.8e)


Memory Leak 3. HMAC_Init()
==========================

    HMAC_CTX hm;

    HMAC_Init(&hm, ...);
    HMAC_Update(&hm, ...);
    HMAC_Final(&hm, ...);
        ...
    HMAC_cleanup(&hm);


    Valgrind reports:

    ==31996==    at 0x4A05809: malloc (vg_replace_malloc.c:149)
    ==31996==    by 0x3C3C6DAD41: CRYPTO_malloc (in
/lib64/libcrypto.so.0.9.8e)
    ==31996==    by 0x3C3C6D8A1D: EVP_DigestInit_ex (in
/lib64/libcrypto.so.0.9.8e)
    ==31996==    by 0x3C3C6EB36B: HMAC_Init_ex (in
/lib64/libcrypto.so.0.9.8e)




______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@...
Automated List Manager                           majordomo@...

Re: Memory leaks...

by Wim Lewis-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Nov 7, 2009, at 2:50 PM, barcaroller wrote:
> I'm getting some memory leaks when I use OpenSSL.  I was not able to  
> get rid
> of these leaks, even when I use EVP_cleanup() and ERR_free_strings()  
> at the
> end of my program.
[....]
>
>    ==27769== 24 bytes in 1 blocks are still reachable in loss record  
> 2 of 20

I'm guessing these are all ENGINEs which were lazily created the first  
time they were needed. Notice that they're "still reachable", so  
they're not necessarily leaks in the usual sense. Have you tried  
calling ENGINE_cleanup()?

The apps.h header in the openssl distribution has a macro which uses  
this sequence for shutdown:

   CONF_modules_unload(1);
   EVP_cleanup();
   ENGINE_cleanup();
   CRYPTO_cleanup_all_ex_data();
   ERR_remove_state(0);
   ERR_free_strings();

Other cleanup methods include:

   OBJ_cleanup();
   COMP_zlib_cleanup();
   RAND_cleanup();

....but I'm rather unclear on which need to be called.


______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@...
Automated List Manager                           majordomo@...