| From: | Michael Paquier <michael(at)paquier(dot)xyz> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Fix shared refcount leak in pgstat entry acquisition |
| Date: | 2026-08-07 05:52:21 |
| Message-ID: | E1wsDVF-00000000XOL-3IKK@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
Fix shared refcount leak in pgstat entry acquisition
pgstat_acquire_entry_ref() does an entry acquisition with the following
actions:
- Increment of a shared ebtr's refcount.
- Release dshash partition lock.
- Update local entry_ref fields.
With a pending interrupt, the LWLock acquired by dshash_release_lock()
in the second step could fail, leaving around a local entry_ref with
shared_stats set to NULL and the refcount permanently inflated as
pgstat_release_entry_ref() skips the refcount decrement is shared_stats
is not set.
The actions are now reordered so as the lock is released after the local
entry_ref fields are populated.
The consequence of this problem is a minor leak. It can only happen if
an interrupt is processed when a dshash lock is released, which is a
very narrow window (very unlikely), so no backpatch is done.
Author: Niall Newman <nn(at)turacolabs(dot)com>
Discussion: https://postgr.es/m/2FDAA194-9CF3-4FD7-A450-F1A4BEB125F6@turacolabs.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/bf80a4c2d238834073b09c231294c4479157f16e
Modified Files
--------------
src/backend/utils/activity/pgstat_shmem.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Amit Langote | 2026-08-07 07:28:27 | pgsql: Remove stale comment on ri_FastPathCheck() |
| Previous Message | Michael Paquier | 2026-08-07 05:24:12 | pgsql: Fix local pgstat entry leak on OOM during entry creation |