Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 701dcc9

Browse files
committed
Fix rare core dump in BackendIdGetTransactionIds().
BackendIdGetTransactionIds() neglected the possibility that the PROC pointer in a ProcState array entry is null. In current usage, this could only crash if the other backend had exited since pgstat_read_current_status saw it as active, which is a pretty narrow window. But it's reachable in the field, per bug #12918 from Vladimir Borodin. Back-patch to 9.4 where the faulty code was introduced.
1 parent 0633a60 commit 701dcc9

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/backend/storage/ipc/sinvaladt.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,7 @@ BackendIdGetProc(int backendID)
403403
void
404404
BackendIdGetTransactionIds(int backendID, TransactionId *xid, TransactionId *xmin)
405405
{
406-
ProcState *stateP;
407406
SISeg *segP = shmInvalBuffer;
408-
PGXACT *xact;
409407

410408
*xid = InvalidTransactionId;
411409
*xmin = InvalidTransactionId;
@@ -415,11 +413,16 @@ BackendIdGetTransactionIds(int backendID, TransactionId *xid, TransactionId *xmi
415413

416414
if (backendID > 0 && backendID <= segP->lastBackend)
417415
{
418-
stateP = &segP->procState[backendID - 1];
419-
xact = &ProcGlobal->allPgXact[stateP->proc->pgprocno];
416+
ProcState *stateP = &segP->procState[backendID - 1];
417+
PGPROC *proc = stateP->proc;
420418

421-
*xid = xact->xid;
422-
*xmin = xact->xmin;
419+
if (proc != NULL)
420+
{
421+
PGXACT *xact = &ProcGlobal->allPgXact[proc->pgprocno];
422+
423+
*xid = xact->xid;
424+
*xmin = xact->xmin;
425+
}
423426
}
424427

425428
LWLockRelease(SInvalWriteLock);

0 commit comments

Comments
 (0)