how to correctly react on exception in pfree function? - Mailing list pgsql-hackers

From Pavel Stehule
Subject how to correctly react on exception in pfree function?
Date
Msg-id CAFj8pRB2+pVBFsidS-AzhHdZid40OTUspWfXS0vgahHmaWosZQ@mail.gmail.com
Whole thread Raw
Responses Re: how to correctly react on exception in pfree function?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hi

I had a talk with Julien about the correct handling of an exception raised by pfree function.

Currently, this exception (elog(ERROR, "could not find block containing chunk %p", chunk);) is not specially handled ever. Because the check of pointer sanity is executed first (before any memory modification), then it is safe to repeatedly call pfree (but if I read code correctly, this behavior is not asserted or tested).

The question is - What is the correct action on this error. In the end, this exception means detection of memory corruption. One, and probably safe way is raising FATAL error.  But it looks like too hard a solution and not too friendly. Moreover, this way is not used in the current code base. 

The traditional solution is just raising the exception and doing nothing more. I didn't find code, where the exception from pfree is exactly handled. Similar issues with the possible exception from pfree can be in plan cache, plpgsql code cache, partially in implementation of update of plpgsql variable. Everywhere the implementation is not too strict - just the exception is raised, but the session continues (although in this moment we know so some memory is corrupted).

Is it a common strategy in Postgres?

Regards

Pavel

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: Summary function for pg_buffercache
Next
From: Andres Freund
Date:
Subject: Re: Tracking last scan time