"Robert A. Knop Jr." <rknop(at)lilys(dot)lbl(dot)gov> writes:
>>>> No. Unless the doc for the function explicitly says you should free
>>>> its result, it's a pointer into libpq-managed space.
>> Experience contradicts this.
>> 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.
I don't understand how. In recent versions, not only is the pointer
you get back not a freshly-malloced chunk, it's not a malloc chunk at
all, but a pointer into the middle of a much larger malloc chunk.
You must have an extremely forgiving malloc library, one wherein free()
doesn't crash if handed a pointer that doesn't point at a malloc chunk.
>> Is there a Postgres developer who can confirm this one way or the other?
I am a Postgres developer, and if you don't want to take my word for it,
read the source code. src/interfaces/libpq/fe-exec.c sez:
PQgetvalue(const PGresult *res, int tup_num, int field_num)
if (!check_tuple_field_number("PQgetvalue", res, tup_num, field_num))
PQfname(const PGresult *res, int field_num)
if (!check_field_number("PQfname", res, field_num))
Actual loading of the PGresult structure is elsewhere in the same file,
but you can certainly see that you're not getting your very own copy
regards, tom lane
In response to
- Re: at 2000-06-30 17:59:07 from Robert A. Knop Jr.
- Re: at 2000-06-30 23:15:20 from Robert A. Knop Jr.
pgsql-interfaces by date
|Next:||From: Robert A. Knop Jr.||Date: 2000-06-30 23:15:20|
|Subject: Re: |
|Previous:||From: Robert A. Knop Jr.||Date: 2000-06-30 17:59:07|
|Subject: Re: |