Re: how to correctly react on exception in pfree function?

Поиск
Список
Период
Сортировка
От Julien Rouhaud
Тема Re: how to correctly react on exception in pfree function?
Дата
Msg-id Y0dw9eB4J0UIdmjr@jrouhaud
обсуждение исходный текст
Ответ на Re: how to correctly react on exception in pfree function?  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: how to correctly react on exception in pfree function?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
On Wed, Oct 12, 2022 at 07:24:53PM -0400, Tom Lane wrote:
> Pavel Stehule <pavel.stehule@gmail.com> writes:
> > 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.
> 
> There are hundreds, if not thousands, of "shouldn't ever happen" elogs
> in Postgres.  We don't make any attempt to trap any of them.  Why do
> you think this one should be different?

Because session variables are allocated in a persistent memory context, so
there's a code doing something like this to implement LET variable:

[...]
oldctxt = MemoryContextSwitchTo(SomePersistentContext);
newval = palloc(...);
MemoryContextSwitchTo(oldctxt);
/* No error should happen after that point or we leak memory */
pfree(var->val);
var->val = newval;
return;

Any error thrown in pfree would mean leaking memory forever in that backend.

Is it ok to leak memory in such should-not-happen case or should there be some
safeguard?



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

Предыдущее
От: Michael Paquier
Дата:
Сообщение: Re: Issue in GIN fast-insert: XLogBeginInsert + Read/LockBuffer ordering
Следующее
От: Tom Lane
Дата:
Сообщение: Re: how to correctly react on exception in pfree function?