postgres.git / summary / log / commit / refs
commit e32c5f118ec2da80fd76da1241dd721ceb3e9127
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: Sun Sep 20 20:48:44 2015 +0000
First released in: 9.6.0, 9.0.23, 9.1.19, 9.2.14, 9.3.10, 9.4.5, 9.5.0
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 1785acebf2ed14fd66955e2d9a55d77a025f418d), 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.
src/backend/storage/lmgr/lock.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c
index c0dd84b3ba9..3e33bc104d3 100644
--- a/src/backend/storage/lmgr/lock.c
+++ b/src/backend/storage/lmgr/lock.c
@@ -758,7 +758,7 @@ LockAcquireExtended(const LOCKTAG *locktag,
locallock->numLockOwners = 0;
locallock->maxLockOwners = 8;
locallock->holdsStrongLockCount = FALSE;
- locallock->lockOwners = NULL;
+ locallock->lockOwners = NULL; /* in case next line fails */
locallock->lockOwners = (LOCALLOCKOWNER *)
MemoryContextAlloc(TopMemoryContext,
locallock->maxLockOwners * sizeof(LOCALLOCKOWNER));
@@ -1227,7 +1227,9 @@ RemoveLocalLock(LOCALLOCK *locallock)
if (locallock->lockOwners[i].owner != NULL)
ResourceOwnerForgetLock(locallock->lockOwners[i].owner, locallock);
}
- pfree(locallock->lockOwners);
+ locallock->numLockOwners = 0;
+ if (locallock->lockOwners != NULL)
+ pfree(locallock->lockOwners);
locallock->lockOwners = NULL;
if (locallock->holdsStrongLockCount)
[parent: f38070d63014]