From c8c952ce2a77343b6fe87a9534026b4b34011322 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sat, 4 May 2013 23:16:59 +0200 Subject: Issue #14173: Avoid crashing when reading a signal handler during interpreter shutdown. --- Misc/NEWS | 3 +++ Modules/signalmodule.c | 14 +++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index 6a3f17c..da68f26 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -47,6 +47,9 @@ Core and Builtins Library ------- +- Issue #14173: Avoid crashing when reading a signal handler during + interpreter shutdown. + - Issue #16316: mimetypes now recognizes the .xz and .txz (.tar.xz) extensions. - Issue #15902: Fix imp.load_module() accepting None as a file when loading an diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index 0cc7237..fbe1bb7 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -344,7 +344,10 @@ signal_signal(PyObject *self, PyObject *args) Handlers[sig_num].tripped = 0; Py_INCREF(obj); Handlers[sig_num].func = obj; - return old_handler; + if (old_handler != NULL) + return old_handler; + else + Py_RETURN_NONE; } PyDoc_STRVAR(signal_doc, @@ -372,8 +375,13 @@ signal_getsignal(PyObject *self, PyObject *args) return NULL; } old_handler = Handlers[sig_num].func; - Py_INCREF(old_handler); - return old_handler; + if (old_handler != NULL) { + Py_INCREF(old_handler); + return old_handler; + } + else { + Py_RETURN_NONE; + } } PyDoc_STRVAR(getsignal_doc, -- cgit v0.12