aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Riggs <simon@2ndQuadrant.com>2010-01-28 10:05:37 +0000
committerSimon Riggs <simon@2ndQuadrant.com>2010-01-28 10:05:37 +0000
commitbcd8528f001f723d6c93648f5386152846384830 (patch)
treea6199deedf7c0bd4178c43ecd535850efc4efb94 /src
parente0e8b9634555f876570d3c1596a50419848a1046 (diff)
downloadpostgresql-bcd8528f001f723d6c93648f5386152846384830.tar.gz
postgresql-bcd8528f001f723d6c93648f5386152846384830.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/backend/storage/lmgr/lock.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c
index ea781a8b29c..2c024f82993 100644
--- a/src/backend/storage/lmgr/lock.c
+++ b/src/backend/storage/lmgr/lock.c
@@ -8,7 +8,7 @@
*
*
* 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
* A lock table is a shared memory hash table. When
@@ -1790,7 +1790,7 @@ LockReassignCurrentOwner(void)
VirtualTransactionId *
GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode)
{
- VirtualTransactionId *vxids;
+ static VirtualTransactionId *vxids = NULL;
LOCKMETHODID lockmethodid = locktag->locktag_lockmethodid;
LockMethod lockMethodTable;
LOCK *lock;
@@ -1812,8 +1812,22 @@ GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode)
* need enough space for MaxBackends + a terminator, since prepared xacts
* don't count.
*/
- vxids = (VirtualTransactionId *)
- palloc0(sizeof(VirtualTransactionId) * (MaxBackends + 1));
+ if (!InHotStandby)
+ 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.