Re: BUG #2260: PGCrypto Memory Problem

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Michael Fuhr <mike@fuhr.org>
Cc: Daniel Blaisdell <lunk.djedi@gmail.com>, pgsql-bugs@postgresql.org, Marko Kreen <marko@l-t.ee>
Date: 2006-02-15T20:02:45Z
Lists: 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