Re: Error in recent pg_dump change (coverity) - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Error in recent pg_dump change (coverity)
Date
Msg-id 17688.1148832033@sss.pgh.pa.us
Whole thread Raw
In response to Re: Error in recent pg_dump change (coverity)  (Alvaro Herrera <alvherre@commandprompt.com>)
Responses Re: Error in recent pg_dump change (coverity)
List pgsql-hackers
Alvaro Herrera <alvherre@commandprompt.com> writes:
> Martijn van Oosterhout wrote:
>> I'd actually suggest zeroing out res->tuples in PQclear so this sort of
>> problem becomes much more obvious.

> Is it worthwhile to zero out the res->block array as well?

Your patch isn't doing that, merely zeroing a local variable
that will be assigned to in a moment anyway.  That loop already
ensures that res->curBlock is null when it exits.  So lose this:

+         block = NULL;

This part seems OK:
     /* Free the top-level tuple pointer array */     if (res->tuples)
+     {         free(res->tuples);
+         res->tuples = NULL;
+     }

Another possibility is to just MemSet the whole PGresult struct
to zeroes before free'ing it.  Compared to the cost of obtaining
a query result from the backend, this probably doesn't cost enough
to be worth worrying about, and it would catch a few more problems
of the same ilk.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: osprey buildfarm member has been failing for a long while
Next
From: Martijn van Oosterhout
Date:
Subject: Re: Error in recent pg_dump change (coverity)