Re:

From: "Robert A(dot) Knop Jr(dot)" <rknop(at)lilys(dot)lbl(dot)gov>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: Re:
Date: 2000-06-30 17:59:07
Message-ID: Pine.LNX.4.10.10006301048490.30121-100000@milano.lbl.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

Wait -- ignore me, I think I was wrong.

I still can't figure out where my memory leak is coming in, but it seems
to be either something so dumb in my code that I can't see it, or
something obscure having to do with the operator= method of the C++ STL
"string" class (when setting a string equal to a char*).

-Rob

On Fri, 30 Jun 2000, Robert A. Knop Jr. wrote:

> "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
>
> > "Robert A. Knop Jr." <rknop(at)lilys(dot)lbl(dot)gov> writes:
> > > If one uses libpq functions such as PQfname, should one free the
> > > returned character string?
> >
> > No. Unless the doc for the function explicitly says you should free
> > its result, it's a pointer into libpq-managed space.
>
> Huh.
>
> Experience contradicts this. I was getting back the results from
> PQgetvalue(), and copying them to a C++ string. I wasn't bothering to
> free what I got back from PQgetvalue(), figuring that based on this,
> anything that PQgetvalue() was pointing at would be freed I called
> PQclear() on the PGresult structure I had passed to PQgetvalue(). In so
> doing, I had a memory leak.
>
> I rewrote the thing explicitly freeing everything I got back from
> PQfname() and PQgetvalue(). The memory leak was gone, and I didn't get
> any segfaults or crashes.
>
> Although this contradicts the documentation on PQgetvalue(), and also
> what was said here, based on experience it looks like that in fact one
> *must* free the character arrays one gets back from those functions.
>
> Is there a Postgres developer who can confirm this one way or the other?
> This should defintely be documented in the libpq documentation.
>
> Note that I'm using Postgres 6.5.2 -- has this behavior changed with
> version 7?
>
> -Rob
>
>

In response to

  • at 2000-06-30 17:33:09 from Robert A. Knop Jr.

Responses

  • Re: at 2000-06-30 18:20:28 from Tom Lane

Browse pgsql-interfaces by date

  From Date Subject
Next Message Tom Lane 2000-06-30 18:20:28 Re:
Previous Message Robert A. Knop Jr. 2000-06-30 17:33:09