aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2014-04-25 15:59:57 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2014-04-25 15:59:57 -0400
commit4bfc5f1396b18da3a0db73e4406badc4ce793a1e (patch)
treec0d169da9570c2703f9db56b6bbb500629e2fc0e /src
parent49137ec9d469f744289d0dfa2487a7fc1ef217cb (diff)
downloadpostgresql-4bfc5f1396b18da3a0db73e4406badc4ce793a1e.tar.gz
postgresql-4bfc5f1396b18da3a0db73e4406badc4ce793a1e.zip
Fix off-by-one bug in LWLockRegisterTranche().
Original coding failed to enlarge the array as required if the requested tranche_id was equal to LWLockTranchesAllocated. In passing, fix poor style of not casting the result of (re)palloc.
Diffstat (limited to 'src')
-rw-r--r--src/backend/storage/lmgr/lwlock.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index 36b4b8bbeaa..df8f9bfd893 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -350,8 +350,9 @@ CreateLWLocks(void)
if (LWLockTrancheArray == NULL)
{
LWLockTranchesAllocated = 16;
- LWLockTrancheArray = MemoryContextAlloc(TopMemoryContext,
- LWLockTranchesAllocated * sizeof(LWLockTranche *));
+ LWLockTrancheArray = (LWLockTranche **)
+ MemoryContextAlloc(TopMemoryContext,
+ LWLockTranchesAllocated * sizeof(LWLockTranche *));
}
MainLWLockTranche.name = "main";
@@ -423,11 +424,12 @@ LWLockRegisterTranche(int tranche_id, LWLockTranche *tranche)
{
int i = LWLockTranchesAllocated;
- while (i < tranche_id)
+ while (i <= tranche_id)
i *= 2;
- LWLockTrancheArray = repalloc(LWLockTrancheArray,
- i * sizeof(LWLockTranche *));
+ LWLockTrancheArray = (LWLockTranche **)
+ repalloc(LWLockTrancheArray,
+ i * sizeof(LWLockTranche *));
LWLockTranchesAllocated = i;
}