pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Robert A. Knop Jr. <rknop@lilys.lbl.gov>
Cc: pgsql-interfaces@postgresql.org
Subject: Re:
Date: Fri, 30 Jun 2000 14:20:28 -0400
Message-ID: <19918.962389228@sss.pgh.pa.us> (raw)
In-Reply-To: <Pine.LNX.4.10.10006301048490.30121-100000@milano.lbl.gov>
References: <Pine.LNX.4.10.10006301048490.30121-100000@milano.lbl.gov>

"Robert A. Knop Jr." <rknop@lilys.lbl.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



view thread (5+ messages)  latest in thread

Message-ID: <19918.962389228@sss.pgh.pa.us>
Permalink:  ../19918.962389228@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/19918.962389228@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: tgl@sss.pgh.pa.us, rknop@lilys.lbl.gov
  Subject: Re:
  In-Reply-To: <19918.962389228@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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