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

"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

Responses

  • Re: at 2000-06-30 17:59:07 from Robert A. Knop Jr.

Browse pgsql-interfaces by date

  From Date Subject
Next Message Robert A. Knop Jr. 2000-06-30 17:59:07 Re:
Previous Message Guoben Li 2000-06-30 16:43:31 JDBC: Class.forName() Fails