From 5d807a74bf66ba9fb4f55e49e7c601b0b9804123 Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Fri, 31 Jan 2014 21:31:08 -0500 Subject: Clear MyProc and MyProcSignalState before they become invalid. Evidence from buildfarm member crake suggests that the new test_shm_mq module is routinely crashing the server due to the arrival of a SIGUSR1 after the shared memory segment has been unmapped. Although processes using the new dynamic background worker facilities are more likely to receive a SIGUSR1 around this time, the problem is also possible on older branches, so I'm back-patching the parts of this change that apply to older branches as far as they apply. It's already generally the case that code checks whether these pointers are NULL before deferencing them, so the important thing is mostly to make sure that they do get set to NULL before they become invalid. But in master, there's one case in procsignal_sigusr1_handler that lacks a NULL guard, so add that. Patch by me; review by Tom Lane. --- src/backend/storage/ipc/procsignal.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/backend/storage/ipc/procsignal.c') diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c index a6f77c105c2..941b678451d 100644 --- a/src/backend/storage/ipc/procsignal.c +++ b/src/backend/storage/ipc/procsignal.c @@ -140,6 +140,13 @@ CleanupProcSignalState(int status, Datum arg) slot = &ProcSignalSlots[pss_idx - 1]; Assert(slot == MyProcSignalSlot); + /* + * Clear MyProcSignalSlot, so that a SIGUSR1 received after this point + * won't try to access it after it's no longer ours (and perhaps even + * after we've unmapped the shared memory segment). + */ + MyProcSignalSlot = NULL; + /* sanity check */ if (slot->pss_pid != MyProcPid) { -- cgit v1.2.3