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.
This commit is contained in:
parent
44297a058e
commit
eed5bbc480
@ -644,7 +644,7 @@ LockAcquireExtended(const LOCKTAG *locktag,
|
|||||||
locallock->nLocks = 0;
|
locallock->nLocks = 0;
|
||||||
locallock->numLockOwners = 0;
|
locallock->numLockOwners = 0;
|
||||||
locallock->maxLockOwners = 8;
|
locallock->maxLockOwners = 8;
|
||||||
locallock->lockOwners = NULL;
|
locallock->lockOwners = NULL; /* in case next line fails */
|
||||||
locallock->lockOwners = (LOCALLOCKOWNER *)
|
locallock->lockOwners = (LOCALLOCKOWNER *)
|
||||||
MemoryContextAlloc(TopMemoryContext,
|
MemoryContextAlloc(TopMemoryContext,
|
||||||
locallock->maxLockOwners * sizeof(LOCALLOCKOWNER));
|
locallock->maxLockOwners * sizeof(LOCALLOCKOWNER));
|
||||||
@ -994,8 +994,11 @@ LockAcquireExtended(const LOCKTAG *locktag,
|
|||||||
static void
|
static void
|
||||||
RemoveLocalLock(LOCALLOCK *locallock)
|
RemoveLocalLock(LOCALLOCK *locallock)
|
||||||
{
|
{
|
||||||
pfree(locallock->lockOwners);
|
locallock->numLockOwners = 0;
|
||||||
|
if (locallock->lockOwners != NULL)
|
||||||
|
pfree(locallock->lockOwners);
|
||||||
locallock->lockOwners = NULL;
|
locallock->lockOwners = NULL;
|
||||||
|
|
||||||
if (!hash_search(LockMethodLocalHash,
|
if (!hash_search(LockMethodLocalHash,
|
||||||
(void *) &(locallock->tag),
|
(void *) &(locallock->tag),
|
||||||
HASH_REMOVE, NULL))
|
HASH_REMOVE, NULL))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user