Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2897e06

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 f444de5 commit 2897e06

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
@@ -410,9 +410,7 @@ BackendIdGetProc(int backendID)
410410
void
411411
BackendIdGetTransactionIds(int backendID, TransactionId *xid, TransactionId *xmin)
412412
{
413-
ProcState *stateP;
414413
SISeg *segP = shmInvalBuffer;
415-
PGXACT *xact;
416414

417415
*xid = InvalidTransactionId;
418416
*xmin = InvalidTransactionId;
@@ -422,11 +420,16 @@ BackendIdGetTransactionIds(int backendID, TransactionId *xid, TransactionId *xmi
422420

423421
if (backendID > 0 && backendID <= segP->lastBackend)
424422
{
425-
stateP = &segP->procState[backendID - 1];
426-
xact = &ProcGlobal->allPgXact[stateP->proc->pgprocno];
423+
ProcState *stateP = &segP->procState[backendID - 1];
424+
PGPROC *proc = stateP->proc;
427425

428-
*xid = xact->xid;
429-
*xmin = xact->xmin;
426+
if (proc != NULL)
427+
{
428+
PGXACT *xact = &ProcGlobal->allPgXact[proc->pgprocno];
429+
430+
*xid = xact->xid;
431+
*xmin = xact->xmin;
432+
}
430433
}
431434

432435
LWLockRelease(SInvalWriteLock);

0 commit comments

Comments
 (0)