Josh Kupershmidt <schmiddy(at)gmail(dot)com> writes:
> Would it be crazy to add an "already_freed" flag to the pg_result
> struct which PQclear() would set, or some equivalent safety mechanism,
> to avoid this hassle for users?
Yes, it would. Once the memory has been freed, malloc() is at liberty
to give it out for some other purpose. The only way we could make that
work reliably is to permanently leak the memory occupied by the PGresult
... which I trust you will agree is a cure worse than the disease.
regards, tom lane