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.
This commit is contained in:
parent
49137ec9d4
commit
4bfc5f1396
@ -350,7 +350,8 @@ CreateLWLocks(void)
|
|||||||
if (LWLockTrancheArray == NULL)
|
if (LWLockTrancheArray == NULL)
|
||||||
{
|
{
|
||||||
LWLockTranchesAllocated = 16;
|
LWLockTranchesAllocated = 16;
|
||||||
LWLockTrancheArray = MemoryContextAlloc(TopMemoryContext,
|
LWLockTrancheArray = (LWLockTranche **)
|
||||||
|
MemoryContextAlloc(TopMemoryContext,
|
||||||
LWLockTranchesAllocated * sizeof(LWLockTranche *));
|
LWLockTranchesAllocated * sizeof(LWLockTranche *));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -423,10 +424,11 @@ 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 **)
|
||||||
|
repalloc(LWLockTrancheArray,
|
||||||
i * sizeof(LWLockTranche *));
|
i * sizeof(LWLockTranche *));
|
||||||
LWLockTranchesAllocated = i;
|
LWLockTranchesAllocated = i;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user