Re: Detecting memory leaks with libpq?

From: dennis jenkins <dennis(dot)jenkins(dot)75(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Detecting memory leaks with libpq?
Date: 2011-07-19 12:56:11
Message-ID: CAAEzAp_B64x627F3j-Q7FOpC9ZgzNJMoNWaA0e5bqwMi76u3Cg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Jul 19, 2011 at 5:41 AM, Antonio Vieiro <antonio(at)antonioshome(dot)net>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.
>

Wrap your main logic in a loop that runs it 100,000 or more times. However,
the process itself should never exit (eg, only ever exist as one pid). As
the process runs, monitor it with top, htop (really nice util for Linux),
vmstat, etc... Does the memory usage go up and up, generally linearly with
time?

Run the same process using "electronic fence" [1] or "valgrind" [2].

[1] http://linux.die.net/man/3/efence (not for finding memory leaks per se,
but useful for finding memory mis-usage.
[2] http://valgrind.org/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Rebecca Clarke 2011-07-19 13:16:34 Database Restore Fail - No liblwgeom.so
Previous Message Craig Ringer 2011-07-19 12:41:38 Re: Identify release contents