Re:
От | Tom Lane |
---|---|
Тема | Re: |
Дата | |
Msg-id | 19918.962389228@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | Re: ("Robert A. Knop Jr." <rknop@lilys.lbl.gov>) |
Ответы |
Re:
|
Список | pgsql-interfaces |
"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
В списке pgsql-interfaces по дате отправления: