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 <[email protected]> Discussion: https://postgr.es/m/[email protected] 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(-)
