Thread: libpq & freeing character results

libpq & freeing character results

From
"Robert A. Knop Jr."
Date:
If one uses libpq functions such as PQfname, should one free the returned
character string?

What I'm really asking is, are you getting a pointer into something
internal to the PGresult structure, which is only valid as long as the
PGresult structure is valid, and which must be copied if it is to exist
after that; or, are you getting a copy of that memory, which is yours to
do with as you please (and your responsibility)?

This is explicitly answered in the documentation for PQgetvalue (it's a
pointer into the PGresult data), so I'm assuming thatt he same applies for
PQfname.  Please let me know if this is a foolish assumption.

-Rob
rknop@lbl.gov




Re: libpq & freeing character results

From
Tom Lane
Date:
"Robert A. Knop Jr." <rknop@lilys.lbl.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.
        regards, tom lane


Perl modules for Perl on NT

From
"Christopher R. Jones"
Date:
Has anyone successfully built the Perl interface module on NT using VC++ (5 
or 6)?

Christopher R. Jones, P.Eng.
14 Oneida Avenue
Toronto, Ontario M5J 2E3
Tel. 416 203-7465
Fax. 416 203-3044
Email cj@interlog.com




Re: libpq & freeing character results

From
tomas@mamma.varadinet.de
Date:
On Tue, Jun 27, 2000 at 12:06:44PM -0700, Robert A. Knop Jr. wrote:
> If one uses libpq functions such as PQfname, should one free the returned
> character string?
> 
[...]
> This is explicitly answered in the documentation for PQgetvalue (it's a
> pointer into the PGresult data), so I'm assuming thatt he same applies for
> PQfname.  Please let me know if this is a foolish assumption.
> 
It does correspond to the general style of the interface -- and peeking
into the implementation...

======================================================================     /*        returns NULL if the field_num is
invalid    */     char *     PQfname(PGresult *res, int field_num)     {             if (!check_field_number("PQfname",
res,field_num))                     return NULL;             if (res->attDescs)                     return
res->attDescs[field_num].name;            else                     return NULL;     }
 
======================================================================
(from src/interfaces/libpq/fe-exec.c; it's version 6.5.3, but I don't
think it has changed) confirms the conjecture.

Regards
-- 
tomas