Skip to content

bpo-38037: Fix reference counters in signal module #15753

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from Sep 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix reference counters in the :mod:`signal` module.
25 changes: 17 additions & 8 deletions Modules/signalmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ static struct PyModuleDef signalmodule = {
PyMODINIT_FUNC
PyInit__signal(void)
{
PyObject *m, *d, *x;
PyObject *m, *d;
int i;

/* Create the module and add the functions */
Expand All @@ -1350,13 +1350,17 @@ PyInit__signal(void)
/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);

x = DefaultHandler = PyLong_FromVoidPtr((void *)SIG_DFL);
if (PyModule_AddObject(m, "SIG_DFL", x))
DefaultHandler = PyLong_FromVoidPtr((void *)SIG_DFL);
if (!DefaultHandler ||
PyDict_SetItemString(d, "SIG_DFL", DefaultHandler) < 0) {
goto finally;
}

x = IgnoreHandler = PyLong_FromVoidPtr((void *)SIG_IGN);
if (PyModule_AddObject(m, "SIG_IGN", x))
IgnoreHandler = PyLong_FromVoidPtr((void *)SIG_IGN);
if (!IgnoreHandler ||
PyDict_SetItemString(d, "SIG_IGN", IgnoreHandler) < 0) {
goto finally;
}

if (PyModule_AddIntMacro(m, NSIG))
goto finally;
Expand All @@ -1374,8 +1378,8 @@ PyInit__signal(void)
goto finally;
#endif

x = IntHandler = PyDict_GetItemString(d, "default_int_handler");
if (!x)
IntHandler = PyDict_GetItemString(d, "default_int_handler");
if (!IntHandler)
goto finally;
Py_INCREF(IntHandler);

Expand Down Expand Up @@ -1568,8 +1572,10 @@ PyInit__signal(void)
#if defined (HAVE_SETITIMER) || defined (HAVE_GETITIMER)
ItimerError = PyErr_NewException("signal.ItimerError",
PyExc_OSError, NULL);
if (PyModule_AddObject(m, "ItimerError", ItimerError))
if (!ItimerError ||
PyDict_SetItemString(d, "ItimerError", ItimerError) < 0) {
goto finally;
}
#endif

#ifdef CTRL_C_EVENT
Expand Down Expand Up @@ -1615,6 +1621,9 @@ finisignal(void)
Py_CLEAR(IntHandler);
Py_CLEAR(DefaultHandler);
Py_CLEAR(IgnoreHandler);
#ifdef HAVE_GETITIMER
Py_CLEAR(ItimerError);
#endif
}


Expand Down