Re: Error in recent pg_dump change (coverity)

Поиск
Список
Период
Сортировка
От Alvaro Herrera
Тема Re: Error in recent pg_dump change (coverity)
Дата
Msg-id 20060528164735.GB11881@surnet.cl
обсуждение исходный текст
Ответ на Re: Error in recent pg_dump change (coverity)  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Error in recent pg_dump change (coverity)  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Tom Lane wrote:
> Martijn van Oosterhout <kleptog@svana.org> writes:
> > On Sun, May 28, 2006 at 12:00:33PM -0400, Tom Lane wrote:
> >> Another possibility is to just MemSet the whole PGresult struct
> >> to zeroes before free'ing it.
> 
> > Probably better actually, since by setting ntups to zero also,
> > PQgetvalue will return a warning (row number out of range) rather than
> > segfaulting...
> 
> Hm.  But I think we'd *like* it to segfault; the idea is to make the
> user's programming error as obvious as possible.  Is it worth the
> trouble to just zero out the pointer members of the PGresult?

There are only five of them; four need to be zeroed out.


void
PQclear(PGresult *res)
{   PGresult_data *block;
   if (!res)       return;      /* Free all the subsidiary blocks */   while ((block = res->curBlock) != NULL)   {
res->curBlock = block->next;       free(block);   }
 
   /* Free the top-level tuple pointer array */   if (res->tuples)       free(res->tuples);
   /* zero out the pointer fields to catch programming errors */   res->attDesc = NULL;   res->tuples = NULL;
res->noticeHooks= NULL;   res->errFields = NULL;   /* res->curBlock was zeroed out earlier */      /* Free the PGresult
structureitself */   free(res);
 
}

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Error in recent pg_dump change (coverity)
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Error in recent pg_dump change (coverity)