Re: Detecting memory leaks with libpq? - Mailing list pgsql-general

From Craig Ringer
Subject Re: Detecting memory leaks with libpq?
Date
Msg-id 4E25868E.4070204@postnewspapers.com.au
Whole thread Raw
In response to Detecting memory leaks with libpq?  (Antonio Vieiro <antonio@antonioshome.net>)
Responses Re: Detecting memory leaks with libpq?  (Ben Chobot <bench@silentmedia.com>)
List pgsql-general
On 19/07/2011 6:41 PM, Antonio Vieiro wrote:
> Hi all,
>
> I'm building a small C application that uses libpq and I was wondering
> if there's an easy way to detect memory leaks in my code.
>
> I think I'm calling PQclear and friends correctly, but I'd like to
> double-check it. I was wondering if there's a function in libpq to
> check memory-use usage/internals, or something like that.
>
If I genuinely suspected a leak and running the code in a loop showed
continually increasing memory use, I'd use valgrind to try to track it
down. Just like for any other kind of leak checking.

Note that some "leaks" that are reported are _normal_ in most software.
There is absolutely no harm in not free()ing a structure that's
allocated only once during init and never messed with afterwards. The OS
clears the memory anyway, so free()ing it is just a waste of CPU cycles.

What you need to look for is patterns where memory is _repeatedly_
allocated and not free()'d . For that, you need to run quite a few
repetitions within one process so you can tell the difference between
the one-offs and genuine leaks.

--
Craig Ringer

POST Newspapers
276 Onslow Rd, Shenton Park
Ph: 08 9381 3088     Fax: 08 9388 2258
ABN: 50 008 917 717
http://www.postnewspapers.com.au/

pgsql-general by date:

Previous
From: Rebecca Clarke
Date:
Subject: Database Restore Fail - No liblwgeom.so
Next
From: "Abraham, Danny"
Date:
Subject: Re: Identify release contents