Skip to content

Commit ba51774

Browse files
committed
Be more wary about partially-valid LOCALLOCK data in RemoveLocalLock().
RemoveLocalLock() must consider the possibility that LockAcquireExtended() failed to palloc the initial space for a locallock's lockOwners array. I had evidently meant to cope with this hazard when the code was originally written (commit 1785ace), but missed that the pfree needed to be protected with an if-test. Just to make sure things are left in a clean state, reset numLockOwners as well. Per low-memory testing by Andreas Seltenreich. Back-patch to all supported branches.
1 parent 85eda7e commit ba51774

File tree

1 file changed

+4
-2
lines changed
  • src/backend/storage/lmgr

1 file changed

+4
-2
lines changed

src/backend/storage/lmgr/lock.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ LockAcquireExtended(const LOCKTAG *locktag,
753753
locallock->numLockOwners = 0;
754754
locallock->maxLockOwners = 8;
755755
locallock->holdsStrongLockCount = FALSE;
756-
locallock->lockOwners = NULL;
756+
locallock->lockOwners = NULL; /* in case next line fails */
757757
locallock->lockOwners = (LOCALLOCKOWNER *)
758758
MemoryContextAlloc(TopMemoryContext,
759759
locallock->maxLockOwners * sizeof(LOCALLOCKOWNER));
@@ -1222,7 +1222,9 @@ RemoveLocalLock(LOCALLOCK *locallock)
12221222
if (locallock->lockOwners[i].owner != NULL)
12231223
ResourceOwnerForgetLock(locallock->lockOwners[i].owner, locallock);
12241224
}
1225-
pfree(locallock->lockOwners);
1225+
locallock->numLockOwners = 0;
1226+
if (locallock->lockOwners != NULL)
1227+
pfree(locallock->lockOwners);
12261228
locallock->lockOwners = NULL;
12271229

12281230
if (locallock->holdsStrongLockCount)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy