Skip to content

Commit 4bfc5f1

Browse files
committed
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.
1 parent 49137ec commit 4bfc5f1

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/backend/storage/lmgr/lwlock.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,9 @@ CreateLWLocks(void)
350350
if (LWLockTrancheArray == NULL)
351351
{
352352
LWLockTranchesAllocated = 16;
353-
LWLockTrancheArray = MemoryContextAlloc(TopMemoryContext,
354-
LWLockTranchesAllocated * sizeof(LWLockTranche *));
353+
LWLockTrancheArray = (LWLockTranche **)
354+
MemoryContextAlloc(TopMemoryContext,
355+
LWLockTranchesAllocated * sizeof(LWLockTranche *));
355356
}
356357

357358
MainLWLockTranche.name = "main";
@@ -423,11 +424,12 @@ LWLockRegisterTranche(int tranche_id, LWLockTranche *tranche)
423424
{
424425
int i = LWLockTranchesAllocated;
425426

426-
while (i < tranche_id)
427+
while (i <= tranche_id)
427428
i *= 2;
428429

429-
LWLockTrancheArray = repalloc(LWLockTrancheArray,
430-
i * sizeof(LWLockTranche *));
430+
LWLockTrancheArray = (LWLockTranche **)
431+
repalloc(LWLockTrancheArray,
432+
i * sizeof(LWLockTranche *));
431433
LWLockTranchesAllocated = i;
432434
}
433435

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy