Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bcd8528

Browse files
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.
1 parent e0e8b96 commit bcd8528

File tree

1 file changed

+18
-4
lines changed
  • src/backend/storage/lmgr

1 file changed

+18
-4
lines changed

src/backend/storage/lmgr/lock.c

+18-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.191 2010/01/23 16:37:12 sriggs Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.192 2010/01/28 10:05:37 sriggs Exp $
1212
*
1313
* NOTES
1414
* A lock table is a shared memory hash table. When
@@ -1790,7 +1790,7 @@ LockReassignCurrentOwner(void)
17901790
VirtualTransactionId *
17911791
GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode)
17921792
{
1793-
VirtualTransactionId *vxids;
1793+
static VirtualTransactionId *vxids = NULL;
17941794
LOCKMETHODID lockmethodid = locktag->locktag_lockmethodid;
17951795
LockMethod lockMethodTable;
17961796
LOCK *lock;
@@ -1812,8 +1812,22 @@ GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode)
18121812
* need enough space for MaxBackends + a terminator, since prepared xacts
18131813
* don't count.
18141814
*/
1815-
vxids = (VirtualTransactionId *)
1816-
palloc0(sizeof(VirtualTransactionId) * (MaxBackends + 1));
1815+
if (!InHotStandby)
1816+
vxids = (VirtualTransactionId *)
1817+
palloc0(sizeof(VirtualTransactionId) * (MaxBackends + 1));
1818+
else
1819+
{
1820+
if (vxids == NULL)
1821+
{
1822+
vxids = (VirtualTransactionId *)
1823+
malloc(sizeof(VirtualTransactionId) * (MaxBackends + 1));
1824+
if (vxids == NULL)
1825+
ereport(ERROR,
1826+
(errcode(ERRCODE_OUT_OF_MEMORY),
1827+
errmsg("out of memory")));
1828+
1829+
}
1830+
}
18171831

18181832
/*
18191833
* Look up the lock object matching the tag.

0 commit comments

Comments
 (0)