pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedlibpq & freeing character results
3+ messages / 3 participants
[nested] [flat]
* libpq & freeing character results
@ 2000-06-27 19:06 Robert A. Knop Jr. <rknop@lilys.lbl.gov>
2000-06-27 20:20 ` Re: libpq & freeing character results tomas@mamma.varadinet.de
2000-06-27 21:36 ` Re: libpq & freeing character results Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 2 replies; 3+ messages in thread
From: Robert A. Knop Jr. @ 2000-06-27 19:06 UTC (permalink / raw)
To: pgsql-interfaces
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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: libpq & freeing character results
2000-06-27 19:06 libpq & freeing character results Robert A. Knop Jr. <rknop@lilys.lbl.gov>
@ 2000-06-27 20:20 ` tomas@mamma.varadinet.de
1 sibling, 0 replies; 3+ messages in thread
From: tomas@mamma.varadinet.de @ 2000-06-27 20:20 UTC (permalink / raw)
To: Robert A. Knop Jr. <rknop@lilys.lbl.gov>; +Cc: pgsql-interfaces
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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: libpq & freeing character results
2000-06-27 19:06 libpq & freeing character results Robert A. Knop Jr. <rknop@lilys.lbl.gov>
@ 2000-06-27 21:36 ` Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 3+ messages in thread
From: Tom Lane @ 2000-06-27 21:36 UTC (permalink / raw)
To: Robert A. Knop Jr. <rknop@lilys.lbl.gov>; +Cc: pgsql-interfaces
"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
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2000-06-27 21:36 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-06-27 19:06 libpq & freeing character results Robert A. Knop Jr. <rknop@lilys.lbl.gov>
2000-06-27 20:20 ` tomas@mamma.varadinet.de
2000-06-27 21:36 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox