From: | Julien Rouhaud <rjuju123(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: how to correctly react on exception in pfree function? |
Date: | 2022-10-13 01:59:17 |
Message-ID: | Y0dw9eB4J0UIdmjr@jrouhaud |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Wed, Oct 12, 2022 at 07:24:53PM -0400, Tom Lane wrote:
> Pavel Stehule <pavel(dot)stehule(at)gmail(dot)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?
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2022-10-13 02:34:29 | Re: how to correctly react on exception in pfree function? |
Previous Message | Michael Paquier | 2022-10-13 01:24:46 | Re: Issue in GIN fast-insert: XLogBeginInsert + Read/LockBuffer ordering |