Re: Fix unsafe coding in ResourceOwnerReleaseAll()

From: Rahila Syed <rahilasyed90(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Subject: Re: Fix unsafe coding in ResourceOwnerReleaseAll()
Date: 2026-06-25 04:49:36
Message-ID: CAH2L28vgFj4kkLNgcMNz85z4k0FXZVOeR7ruLhy_v2Z4sMF7Ow@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Tom,

Thank you for proposing this change.

>
> Of course, this might lead to leaking the resource we wished to free.
> But that's better than crashing, or at least that's the value judgment
> we made long ago in the original ResourceOwner code.
>

Another approach would be to remove the resource from the resource
owner's list directly within the ResourceRelease callbacks, just
before the resource is released.
This makes the fix specific to a resource type rather than applying it
across all resource types. This would be similar to how it's done in
ReleaseCatCacheWithOwner.

That said, the patch looks good because it makes the code consistent
with ResourceOwnerReleaseAllOfKind() and avoids the crash.

Unrelated to the patch but I noticed a typo in the ERROR message in
ResourceOwnerReleaseAllOfKind(). If we
want a check similar to ResourceOwnerForget in this function, we
should edit the ERROR message with the correct
function name.
I can propose a patch for this in a separate thread, if you'd prefer.

The error message is as follows:

> void
> ResourceOwnerReleaseAllOfKind(ResourceOwner owner, const ResourceOwnerDesc *kind)
> {
> /* Mustn't call this after we have already started releasing resources. */
> if (owner->releasing)
> elog(ERROR, "ResourceOwnerForget called for %s after release started", kind->name);

Thank you,
Rahila Syed

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message vignesh C 2026-06-25 05:04:44 Re: Proposal: Conflict log history table for Logical Replication
Previous Message Chao Li 2026-06-25 04:10:26 Re: Small patch to improve safety of utf8_to_unicode().