summaryrefslogtreecommitdiffstats
path: root/Modules/atexitmodule.c
diff options
context:
space:
mode:
authorSkip Montanaro <skip@pobox.com>2008-09-23 00:52:29 (GMT)
committerSkip Montanaro <skip@pobox.com>2008-09-23 00:52:29 (GMT)
commit711552bb40f7a9f74139963a9822b49d853aee31 (patch)
tree28958c804a5978daf7c7472299656623aee6bee7 /Modules/atexitmodule.c
parent9bc9351c0495f78f8350c7fc5368e77b51883330 (diff)
downloadcpython-711552bb40f7a9f74139963a9822b49d853aee31.zip
cpython-711552bb40f7a9f74139963a9822b49d853aee31.tar.gz
cpython-711552bb40f7a9f74139963a9822b49d853aee31.tar.bz2
Fix for issue 3666 - atexit.register with bad inputs segfaults on exit.
Reviewed by Christian Heimes.
Diffstat (limited to 'Modules/atexitmodule.c')
-rw-r--r--Modules/atexitmodule.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/Modules/atexitmodule.c b/Modules/atexitmodule.c
index 5b073cb..be16de4 100644
--- a/Modules/atexitmodule.c
+++ b/Modules/atexitmodule.c
@@ -10,6 +10,8 @@
/* Forward declaration (for atexit_cleanup) */
static PyObject *atexit_clear(PyObject*);
+/* Forward declaration (for atexit_callfuncs) */
+static void atexit_cleanup(void);
/* ===================================================================== */
/* Callback machinery. */
@@ -26,7 +28,7 @@ static int callback_len = 32;
/* Installed into pythonrun.c's atexit mechanism */
-void
+static void
atexit_callfuncs(void)
{
PyObject *exc_type = NULL, *exc_value, *exc_tb, *r;
@@ -60,11 +62,13 @@ atexit_callfuncs(void)
}
}
+ atexit_cleanup();
+
if (exc_type)
PyErr_Restore(exc_type, exc_value, exc_tb);
}
-void
+static void
atexit_delete_cb(int i)
{
atexit_callback *cb = atexit_callbacks[i];
@@ -75,7 +79,7 @@ atexit_delete_cb(int i)
PyMem_Free(cb);
}
-void
+static void
atexit_cleanup(void)
{
PyObject *r = atexit_clear(NULL);
@@ -260,8 +264,5 @@ PyInit_atexit(void)
return NULL;
_Py_PyAtExit(atexit_callfuncs);
- /* Register a callback that will free
- atexit_callbacks, otherwise valgrind will report memory leaks. */
- Py_AtExit(atexit_cleanup);
return m;
}