| From: | "Bret S(dot) Lambert" <bret(dot)lambert(at)gmail(dot)com> |
|---|---|
| To: | Dmitriy Igrishin <dmitigr(at)gmail(dot)com> |
| Cc: | Polyakov Vladimir <vvpolyakov(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org |
| Subject: | Re: Libpq memory leak |
| Date: | 2010-09-24 14:16:57 |
| Message-ID: | 20100924141657.GA8671@FlamingKaty.lan |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
On Fri, Sep 24, 2010 at 06:11:31PM +0400, Dmitriy Igrishin wrote:
> Hey Vladimir,
>
>
>
> 2010/9/24 Polyakov Vladimir <vvpolyakov(at)gmail(dot)com>
>
> > Program written in C using Libpq, which receives large files (BYTEA)
> > has a memory leak.
> > I need to free ALL of the used memory after each sql query.
> >
> > after each call PQclear() I drop the buffer:
> > conn->inBuffer = realloc(conn->inBuffer, 8192);
> > conn->inBufSize = 8192;
This is a known unsafe use of the realloc() function. If if fails to
allocate memory, you just lost the conn->inBuffer, thus leaking memory
in your own code. Fix this first, and then see if you still have the
issue with memory leaks, because it's possible you're just leaking it
with a bad realloc() idiom.
> >
> > It works, but ..
> > I noticed that in some cases PQclear() does not clear the memory.
> > This happens only when the program receives certain files...
> >
> > Why do you need realloc() after PQclear()?
>
> --
> Regards,
> Dmitriy
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Wang, Mary Y | 2010-09-24 14:52:16 | Trade Study on Oracle vs. PostgreSQL |
| Previous Message | Dmitriy Igrishin | 2010-09-24 14:11:31 | Re: Libpq memory leak |