Commit bcd8528f authored by Simon Riggs's avatar Simon Riggs

Use malloc() in GetLockConflicts() when called InHotStandby to avoid repeated

palloc calls. Current code assumed this was already true, so this is a bug fix.
parent e0e8b963
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.191 2010/01/23 16:37:12 sriggs Exp $ * $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.192 2010/01/28 10:05:37 sriggs Exp $
* *
* NOTES * NOTES
* A lock table is a shared memory hash table. When * A lock table is a shared memory hash table. When
...@@ -1790,7 +1790,7 @@ LockReassignCurrentOwner(void) ...@@ -1790,7 +1790,7 @@ LockReassignCurrentOwner(void)
VirtualTransactionId * VirtualTransactionId *
GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode) GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode)
{ {
VirtualTransactionId *vxids; static VirtualTransactionId *vxids = NULL;
LOCKMETHODID lockmethodid = locktag->locktag_lockmethodid; LOCKMETHODID lockmethodid = locktag->locktag_lockmethodid;
LockMethod lockMethodTable; LockMethod lockMethodTable;
LOCK *lock; LOCK *lock;
...@@ -1812,8 +1812,22 @@ GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode) ...@@ -1812,8 +1812,22 @@ GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode)
* need enough space for MaxBackends + a terminator, since prepared xacts * need enough space for MaxBackends + a terminator, since prepared xacts
* don't count. * don't count.
*/ */
vxids = (VirtualTransactionId *) if (!InHotStandby)
palloc0(sizeof(VirtualTransactionId) * (MaxBackends + 1)); vxids = (VirtualTransactionId *)
palloc0(sizeof(VirtualTransactionId) * (MaxBackends + 1));
else
{
if (vxids == NULL)
{
vxids = (VirtualTransactionId *)
malloc(sizeof(VirtualTransactionId) * (MaxBackends + 1));
if (vxids == NULL)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
}
}
/* /*
* Look up the lock object matching the tag. * Look up the lock object matching the tag.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment