Re: BUG #2260: PGCrypto Memory Problem - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #2260: PGCrypto Memory Problem
Date
Msg-id 19064.1140033765@sss.pgh.pa.us
Whole thread Raw
In response to Re: BUG #2260: PGCrypto Memory Problem  (Michael Fuhr <mike@fuhr.org>)
Responses Re: BUG #2260: PGCrypto Memory Problem
List pgsql-bugs
Michael Fuhr <mike@fuhr.org> writes:
> My non-OpenSSL build shows no memory leak, so the leak and OpenSSL
> seem to be correlated.  I'd be more inclined to suspect a bug in
> pgcrypto's OpenSSL-specific code than in OpenSSL itself.  Will keep
> digging.

The problem appears to be here:

static void
digest_finish(PX_MD * h, uint8 *dst)
{
    EVP_MD_CTX *ctx = (EVP_MD_CTX *) h->p.ptr;
    const EVP_MD *md = EVP_MD_CTX_md(ctx);

    EVP_DigestFinal(ctx, dst, NULL);

    /*
     * Some builds of 0.9.7x clear all of ctx in EVP_DigestFinal. Fix it by
     * reinitializing ctx.
     */
    EVP_DigestInit(ctx, md);
}

It looks like this results in a leak of the entire OpenSSL context for
each call to pg_crypt.  Marko, I trust you've got a better solution for
this ...

            regards, tom lane

pgsql-bugs by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: BUG #2260: PGCrypto Memory Problem
Next
From: Daniel Blaisdell
Date:
Subject: Re: BUG #2260: PGCrypto Memory Problem