Received: from sss2.sss.pgh.pa.us (sss.pgh.pa.us [209.114.166.2]) by hub.org (8.10.1/8.10.1) with ESMTP id e5UIKWS78744 for ; Fri, 30 Jun 2000 14:20:32 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss2.sss.pgh.pa.us (8.9.3/8.9.3) with ESMTP id OAA19921; Fri, 30 Jun 2000 14:20:29 -0400 (EDT) To: "Robert A. Knop Jr." cc: pgsql-interfaces@postgresql.org Subject: Re: In-reply-to: References: Comments: In-reply-to "Robert A. Knop Jr." message dated "Fri, 30 Jun 2000 10:59:07 -0700" Date: Fri, 30 Jun 2000 14:20:28 -0400 Message-ID: <19918.962389228@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200006/139 "Robert A. Knop Jr." 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