aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2015-09-20 16:48:44 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2015-09-20 16:48:44 -0400
commitba51774d87a2a0402628f7bd68295c0b2913cc25 (patch)
treeb4d139be65869b173fb95a25f78ee63cb0544d1b /src
parent85eda7e92c936470515b73682cacabe972e69adc (diff)
downloadpostgresql-ba51774d87a2a0402628f7bd68295c0b2913cc25.tar.gz
postgresql-ba51774d87a2a0402628f7bd68295c0b2913cc25.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/backend/storage/lmgr/lock.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c
index 1eb2d4b68da..c377d384b76 100644
--- a/src/backend/storage/lmgr/lock.c
+++ b/src/backend/storage/lmgr/lock.c
@@ -753,7 +753,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));
@@ -1222,7 +1222,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)