Thanks all of you for providing the inputs, and with your help, I think I found 
out the problem.

In my test program I am calling the function "X509_STORE_get_by_subject(ctx, 
X509_LU_CRL, issuer, &obj)" to get the CRL list. But after this function call, 
I didn't use the "X509_OBJECT_free_contents()" to free the contents of the 
returned object "obj". It seems this is the cause of the memory leak. By adding 
"X509_OBJECT_free_contents(&obj)" function, the Purify does not report any 
memory leaks.

Thanks
Bob



-----Original Message-----
From: owner-openssl-us...@openssl.org [mailto:owner-openssl-us...@openssl.org] 
On Behalf Of Chris Dodd
Sent: Friday, June 24, 2011 5:30 PM
To: openssl-users@openssl.org
Subject: Re: Question regarding to memory leak

  On Fri, Jun 24, 2011, Yan, Bob wrote:

>  Hi,
>
>  I have used IBM purify to check my test program which invokes openssl  
> library. There are some memory leaks reported by Purify, please see  
> below. Could somebody point to me from which function those leaks were  
> generated, and how to avoid those leaks? Thanks, Bob
>
>
>  MLK: 1104 bytes leaked in 46 blocks
>  This memory was allocated from:
>  malloc [rtlib.o]
>  CRYPTO_malloc [libcrypto.so.1.0.0]
>  ASN1_STRING_type_new [libcrypto.so.1.0.0]  ASN1_primitive_new 
> [libcrypto.so.1.0.0]  asn1_item_ex_combine_new [libcrypto.so.1.0.0]  
> asn1_item_ex_combine_new [libcrypto.so.1.0.0]  ASN1_item_ex_d2i 
> [libcrypto.so.1.0.0]  asn1_template_noexp_d2i [libcrypto.so.1.0.0]  
> Block of 24 bytes (46 times); last block at 0x2aaaac0f7218

I've used valgrind with OpenSSL based programs to find memory leaks, and with 
it, you can use a "--num-callers=N" option to get deeper stack traces in the 
leak reports.  You need a depth of 15-20 to get far enough to see where your 
code is calling into the OpenSSL code in most cases.

There's probably a similar option for IBM purify.

                 -chris

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

Reply via email to