Commit 4bfc5f13 authored by Tom Lane's avatar Tom Lane

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.
parent 49137ec9
...@@ -350,8 +350,9 @@ CreateLWLocks(void) ...@@ -350,8 +350,9 @@ CreateLWLocks(void)
if (LWLockTrancheArray == NULL) if (LWLockTrancheArray == NULL)
{ {
LWLockTranchesAllocated = 16; LWLockTranchesAllocated = 16;
LWLockTrancheArray = MemoryContextAlloc(TopMemoryContext, LWLockTrancheArray = (LWLockTranche **)
LWLockTranchesAllocated * sizeof(LWLockTranche *)); MemoryContextAlloc(TopMemoryContext,
LWLockTranchesAllocated * sizeof(LWLockTranche *));
} }
MainLWLockTranche.name = "main"; MainLWLockTranche.name = "main";
...@@ -423,11 +424,12 @@ LWLockRegisterTranche(int tranche_id, LWLockTranche *tranche) ...@@ -423,11 +424,12 @@ LWLockRegisterTranche(int tranche_id, LWLockTranche *tranche)
{ {
int i = LWLockTranchesAllocated; int i = LWLockTranchesAllocated;
while (i < tranche_id) while (i <= tranche_id)
i *= 2; i *= 2;
LWLockTrancheArray = repalloc(LWLockTrancheArray, LWLockTrancheArray = (LWLockTranche **)
i * sizeof(LWLockTranche *)); repalloc(LWLockTrancheArray,
i * sizeof(LWLockTranche *));
LWLockTranchesAllocated = i; LWLockTranchesAllocated = i;
} }
......
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