Re: Memory leak somewhere at PQconnectdb?

From: Craig Ringer <ringerc(at)ringerc(dot)id(dot)au>
To: Antonio Vieiro <antonio(at)antonioshome(dot)net>
Cc: pgsql <pgsql-general(at)postgresql(dot)org>
Subject: Re: Memory leak somewhere at PQconnectdb?
Date: 2011-09-02 03:02:07
Message-ID: 4E60472F.7080706@ringerc.id.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 01/09/11 22:08, Antonio Vieiro wrote:
> Hi all,
>
> I'm running one of my programs with valgrind to check for memory leaks
> and I'm seeing something like this:

You only get the one report, though, right? No matter how many times
PQconnectdb is run in a loop?

It's internal stuff within OpenSSL. If you really want to you can call:

CONF_modules_free()

before your program terminates, to make sure OpenSSL cleans up its data
structures. Just make sure nobody else has registered an atexit()
handler that touches OpenSSL or you'll get fireworks.

PostgreSQL (libpq) should not be responsible for cleaning up OpenSSL,
and *cannot* be reliably responsible for it. If libpq tried to clean up
OpenSSL it might well "clean" it while other libraries or the main
application code was still using it for something else.

If you want to avoid this warning, call OPENSSL_config yourself before
doing anything in libpq, and call CONF_modules_free before exit. That
way libpq's call to OPENSSL_config becomes a no-op and you have full
control of OpenSSL's init and cleanup.

Even better, add a valgrind suppressions file for the warnings and
ignore them. They are "leaks" only in the sense that a static variable
is a leak, ie not at all.

If you see that the program grows if you run it many times in a loop,
and you get more and more leak records for every loop, *THEN* there
might be a problem.

--
Craig Ringer

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mike Christensen 2011-09-02 03:52:57 pgAdmin3 not working with Gnome3
Previous Message Bruce Momjian 2011-09-01 23:45:42 Re: pg_upgrade from 8.3.4 issue