diff options
author | Tom Lane | 2015-09-20 20:48:44 +0000 |
---|---|---|
committer | Tom Lane | 2015-09-20 20:48:44 +0000 |
commit | 553ce7e9a8d147cae75f0656a628c29dcbe498d8 (patch) | |
tree | a040dd9e071eed69638edd7f3c909c0c62a86387 | |
parent | a369ef9136885ac2c3eb46439587e1c44a5d302b (diff) |
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.
-rw-r--r-- | src/backend/storage/lmgr/lock.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c index 5269b2d10ea..d5786ca53ae 100644 --- a/src/backend/storage/lmgr/lock.c +++ b/src/backend/storage/lmgr/lock.c @@ -646,7 +646,7 @@ LockAcquireExtended(const LOCKTAG *locktag, locallock->nLocks = 0; locallock->numLockOwners = 0; locallock->maxLockOwners = 8; - locallock->lockOwners = NULL; + locallock->lockOwners = NULL; /* in case next line fails */ locallock->lockOwners = (LOCALLOCKOWNER *) MemoryContextAlloc(TopMemoryContext, locallock->maxLockOwners * sizeof(LOCALLOCKOWNER)); @@ -1004,8 +1004,11 @@ 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 (!hash_search(LockMethodLocalHash, (void *) &(locallock->tag), HASH_REMOVE, NULL)) |