Commit 701dcc98 authored by Tom Lane's avatar Tom Lane

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.
parent 0633a60f
...@@ -403,9 +403,7 @@ BackendIdGetProc(int backendID) ...@@ -403,9 +403,7 @@ BackendIdGetProc(int backendID)
void void
BackendIdGetTransactionIds(int backendID, TransactionId *xid, TransactionId *xmin) BackendIdGetTransactionIds(int backendID, TransactionId *xid, TransactionId *xmin)
{ {
ProcState *stateP;
SISeg *segP = shmInvalBuffer; SISeg *segP = shmInvalBuffer;
PGXACT *xact;
*xid = InvalidTransactionId; *xid = InvalidTransactionId;
*xmin = InvalidTransactionId; *xmin = InvalidTransactionId;
...@@ -415,11 +413,16 @@ BackendIdGetTransactionIds(int backendID, TransactionId *xid, TransactionId *xmi ...@@ -415,11 +413,16 @@ BackendIdGetTransactionIds(int backendID, TransactionId *xid, TransactionId *xmi
if (backendID > 0 && backendID <= segP->lastBackend) if (backendID > 0 && backendID <= segP->lastBackend)
{ {
stateP = &segP->procState[backendID - 1]; ProcState *stateP = &segP->procState[backendID - 1];
xact = &ProcGlobal->allPgXact[stateP->proc->pgprocno]; PGPROC *proc = stateP->proc;
*xid = xact->xid; if (proc != NULL)
*xmin = xact->xmin; {
PGXACT *xact = &ProcGlobal->allPgXact[proc->pgprocno];
*xid = xact->xid;
*xmin = xact->xmin;
}
} }
LWLockRelease(SInvalWriteLock); LWLockRelease(SInvalWriteLock);
......
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