Skip site navigation (1) Skip section navigation (2)

Re:

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Robert A(dot) Knop Jr(dot)" <rknop(at)lilys(dot)lbl(dot)gov>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re:
Date: 2000-06-30 18:20:28
Message-ID: 19918.962389228@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-interfaces
"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:

char *
PQgetvalue(const PGresult *res, int tup_num, int field_num)
{
    if (!check_tuple_field_number("PQgetvalue", res, tup_num, field_num))
        return NULL;
    return res->tuples[tup_num][field_num].value;
}

char *
PQfname(const 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;
}

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
back here.

			regards, tom lane

In response to

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

Responses

  • 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:

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group