I'm still trying to track down some memory leaks and using the following
code I'm see leaks in the OpenSSL library. Could some one please let me
know if I'm making these calls incorrectly, or if there are any patches
(other then upgrading to 0.9.8) that can be applied to fix the leaks. We
are currently using 0.9.7g.
void
process(EVP_PKEY **pubKey)
{
X509 *rootCert = NULL;
FILE *fp;
BIO *fileBio = NULL;
fp =
fopen("/home/dbrock/src/GMSModule/certs/production/cacert.pem","r");
if (fp == NULL)
{
printf("Error could not open root cert\n");
return -1;
}
fileBio = BIO_new(BIO_s_file());
BIO_set_fp(fileBio,fp,BIO_NOCLOSE);
rootCert = PEM_read_bio_X509(fileBio,NULL, NULL, NULL);
if (rootCert == NULL)
{
printf("Error could not open root cert\n");
return -1;
}
/* Pull out the public key */
if ((*pubKey = X509_get_pubkey(rootCert)) == NULL)
{
printf("Error could not get public key\n");
return -1;
}
BIO_free(fileBio);
fileBio = NULL;
(void) fclose(fp);
fp = NULL;
OPENSSL_free(rootCert);
return 0;
}
int
main (int argc, char **argv)
{
EVP_PKEY *pubKey = NULL;
process(&pubKey);
OPENSSL_free(pubKey);
return 0;
}
Valgrind reports:
==7340== by 0x805B8DD: ASN1_template_new (tasn_new.c:271)
==7340== by 0x805B704: asn1_item_ex_combine_new (tasn_new.c:178)
==7340== by 0x805E7DF: ASN1_item_ex_d2i (tasn_dec.c:317)
==7340== by 0x805E9EF: ASN1_item_d2i (tasn_dec.c:115)
==7340== by 0x805AD9A: d2i_X509 (x_x509.c:125)
==7340== by 0x804D0A2: PEM_ASN1_read_bio (pem_oth.c:80)
==7340== by 0x804D044: PEM_read_bio_X509 (pem_x509.c:68)
==7340== by 0x8048FFC: process (hashtest.c:118)
==7340==
==7340==
==7340== 1904 (112 direct, 1792 indirect) bytes in 7 blocks are
definitely lost in loss record 24 of 50
==7340== at 0x1B9052E4: malloc (vg_replace_malloc.c:130)
==7340== by 0x804912F: default_malloc_ex (mem.c:79)
==7340== by 0x8049664: CRYPTO_malloc (mem.c:304)
==7340== by 0x805FB26: ASN1_STRING_type_new (asn1_lib.c:377)
==7340== by 0x805B776: asn1_item_ex_combine_new (tasn_new.c:327)
==7340== by 0x805B8DD: ASN1_template_new (tasn_new.c:271)
==7340== by 0x805B704: asn1_item_ex_combine_new (tasn_new.c:178)
==7340== by 0x805E7DF: ASN1_item_ex_d2i (tasn_dec.c:317)
==7340== by 0x805E9EF: ASN1_item_d2i (tasn_dec.c:115)
==7340== by 0x805AD9A: d2i_X509 (x_x509.c:125)
==7340== by 0x804D0A2: PEM_ASN1_read_bio (pem_oth.c:80)
==7340== by 0x804D044: PEM_read_bio_X509 (pem_x509.c:68)
==7340==
==7340==
==7340== 1876 bytes in 7 blocks are definitely lost in loss record 46 of 50
==7340== at 0x1B9052E4: malloc (vg_replace_malloc.c:130)
==7340== by 0x804912F: default_malloc_ex (mem.c:79)
==7340== by 0x8049664: CRYPTO_malloc (mem.c:304)
==7340== by 0x80545D6: BUF_MEM_grow (buffer.c:110)
==7340== by 0x804DEBF: X509_NAME_oneline (x509_obj.c:85)
==7340== by 0x805AB40: x509_cb (x_x509.c:101)
==7340== by 0x805E3A1: ASN1_item_ex_d2i (tasn_dec.c:398)
==7340== by 0x805E9EF: ASN1_item_d2i (tasn_dec.c:115)
==7340== by 0x805AD9A: d2i_X509 (x_x509.c:125)
==7340== by 0x804D0A2: PEM_ASN1_read_bio (pem_oth.c:80)
==7340== by 0x804D044: PEM_read_bio_X509 (pem_x509.c:68)
==7340== by 0x8048FFC: process (hashtest.c:118)
==7340==
==7340==
==7340== 2800 (588 direct, 2212 indirect) bytes in 7 blocks are
definitely lost in loss record 48 of 50
==7340== at 0x1B9052E4: malloc (vg_replace_malloc.c:130)
==7340== by 0x804912F: default_malloc_ex (mem.c:79)
==7340== by 0x8049664: CRYPTO_malloc (mem.c:304)
==7340== by 0x806D519: RSA_new_method (rsa_lib.c:132)
==7340== by 0x806D7AC: RSA_new (rsa_lib.c:76)
==7340== by 0x806DD44: rsa_cb (rsa_asn1.c:80)
==7340== by 0x805B6B4: asn1_item_ex_combine_new (tasn_new.c:160)
==7340== by 0x805E7DF: ASN1_item_ex_d2i (tasn_dec.c:317)
==7340== by 0x805E9EF: ASN1_item_d2i (tasn_dec.c:115)
==7340== by 0x806DE0A: d2i_RSAPublicKey (rsa_asn1.c:111)
==7340== by 0x805B2CF: d2i_PublicKey (d2i_pu.c:93)
==7340== by 0x8059C17: X509_PUBKEY_get (x_pubkey.c:220)
==7340==
==7340== LEAK SUMMARY:
==7340== definitely lost: 2912 bytes in 35 blocks.
==7340== indirectly lost: 17626 bytes in 630 blocks.
==7340== possibly lost: 0 bytes in 0 blocks.
==7340== still reachable: 340 bytes in 14 blocks.
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List openssl-users@openssl.org
Automated List Manager [EMAIL PROTECTED]