agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Improve GrantLockLocal() handling on out-of-memory errors
Date: Wed, 12 Aug 2026 00:13:46 +0000
Message-ID: <E1wtwbI-00000000BDx-42Zw@gemulon.postgresql.org> (raw)

Improve GrantLockLocal() handling on out-of-memory errors

On the first LockAcquire for a lock tag, LockAcquireExtended() creates
a LOCALLOCK entry in the hash table LockMethodLocalHash, with lockOwners
set to NULL.  lockOwners is then allocated in TopMemoryContext.

If the allocation fails, the hash entry would persist with lockOwners
still NULL and maxLockOwners already set to 8.  A follow-up
LockAcquire() on the same entry would crash on a NULL pointer
dereference.

This commit adds an extra layer of safety for such a case, by
re-attempting MemoryContextAlloc() if a LOCALLOCK entry exists but its
lockOwners is still NULL due to a previous in-flight allocation failure.

This problem is unlikely going to show up in practice, so no backpatch
is done.

Author: Bryan Green <dbryan.green@gmail.com>
Author: Mark Dilger <mark.dilger@enterprisedb.com>
Discussion: https://postgr.es/m/c9a5eeb1-4d31-46e1-bb9e-33448a23a5d3@gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/afd63e0ad23ed826aa953977a5306a3703503afa

Modified Files
--------------
src/backend/storage/lmgr/lock.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)



Message-ID: <E1wtwbI-00000000BDx-42Zw@gemulon.postgresql.org>
Permalink:  ../E1wtwbI-00000000BDx-42Zw@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wtwbI-00000000BDx-42Zw@gemulon.postgresql.org

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: michael@paquier.xyz, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Improve GrantLockLocal() handling on out-of-memory errors
  In-Reply-To: <E1wtwbI-00000000BDx-42Zw@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox