Re: Detecting memory leaks with libpq?

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: Antonio Vieiro <antonio(at)antonioshome(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Detecting memory leaks with libpq?
Date: 2011-07-19 13:28:46
Message-ID: 4E25868E.4070204@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Abraham, Danny 2011-07-19 13:36:02 Re: Identify release contents
Previous Message Rebecca Clarke 2011-07-19 13:16:34 Database Restore Fail - No liblwgeom.so