David Brock wrote:
> 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);

Why don't you simply do a
        BIO *fileBio = 
BIO_new_file("/home/dbrock/src/GMSModule/certs/production/cacert.pem","r");
        if (!fileBio)
                ...

>        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);

X509_free(rootcert);

>        return 0;
> }
> 
> int
> main (int argc, char **argv)
> {
>        EVP_PKEY *pubKey = NULL;
>        process(&pubKey);
>        OPENSSL_free(pubKey);

EVP_PKEY_free(pubkey);

>        return 0;
> }

Bye

Goetz

-- 
DMCA: The greed of the few outweighs the freedom of the many

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to