Re: Memory leak somewhere at PQconnectdb? - Mailing list pgsql-general

From Craig Ringer
Subject Re: Memory leak somewhere at PQconnectdb?
Date
Msg-id 4E60472F.7080706@ringerc.id.au
Whole thread Raw
In response to Memory leak somewhere at PQconnectdb?  (Antonio Vieiro <antonio@antonioshome.net>)
Responses Re: Memory leak somewhere at PQconnectdb?
List 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

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Why schema of table is removed from explain?
Next
From: Diego Augusto Molina
Date:
Subject: Re: How can I merge two tables?