Yeah thanks.. It's my bad to miss such a simple thingy...
The problem was actually my program(more complex than the test case) is
giving the same memory leak. Seems I have to look at my code more
carefully.
Cheers,
Kaushalye
Nick Hudson wrote:
Kaushalye Kapuruge wrote:
Hi,
Somebody please reply to my question... :)
Cheers,
Kaushalye
Kaushalye Kapuruge wrote:
Hi,
I found that there is a memory leak in the function
PEM_read_bio_X509();
Herewith I've attached the valgrind trace(with flags --tool=memcheck
--leak-check=full --show-reachable=yes ) and a sample test case.
Is this a known issue or have I missed some steps?
Cheers,
Kaushalye
------------------------------------------------------------------------
#include <stdio.h>
#include <openssl/rsa.h>
#include <openssl/evp.h>
#include <openssl/objects.h>
#include <openssl/x509.h>
#include <openssl/err.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <openssl/bio.h>
int main ()
{
static char certfile[] = "rsacert.pem";
X509 * cert = NULL;
BIO *bio_cert = NULL;
int ret;
/*Load cert*/
bio_cert = BIO_new_file(certfile, "rb");
PEM_read_bio_X509(bio_cert, &cert, NULL, NULL);
if(!cert){
printf("Cannot load the certificate\n");
}
ret = BIO_reset(bio_cert);
ret = BIO_free(bio_cert);
bio_cert = NULL;
return 0;
}
I think the problem is that you haven't freed the X509 structure
which was created when you read the certificate.
So your program needs something like
if (cert) {
X509_free(cert);
}
at the end.
nick
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List openssl-users@openssl.org
Automated List Manager [EMAIL PROTECTED]
--
http://kaushalye.blogspot.com/
http://wso2.org/
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List openssl-users@openssl.org
Automated List Manager [EMAIL PROTECTED]