Commit 3e81ec8c authored by Collin Winter's avatar Collin Winter

Address some XXXs from Neal Norwitz.

parent ca477b22
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
#include "Python.h" #include "Python.h"
/* Forward declaration (for atexit_cleanup) */
static PyObject *atexit_clear(PyObject*);
/* ===================================================================== */ /* ===================================================================== */
/* Callback machinery. */ /* Callback machinery. */
...@@ -72,6 +75,13 @@ atexit_delete_cb(int i) ...@@ -72,6 +75,13 @@ atexit_delete_cb(int i)
PyMem_Free(cb); PyMem_Free(cb);
} }
void
atexit_cleanup(void)
{
PyObject *r = atexit_clear(NULL);
Py_DECREF(r);
}
/* ===================================================================== */ /* ===================================================================== */
/* Module methods. */ /* Module methods. */
...@@ -93,12 +103,13 @@ atexit_register(PyObject *self, PyObject *args, PyObject *kwargs) ...@@ -93,12 +103,13 @@ atexit_register(PyObject *self, PyObject *args, PyObject *kwargs)
PyObject *func = NULL; PyObject *func = NULL;
if (ncallbacks >= callback_len) { if (ncallbacks >= callback_len) {
atexit_callback **r;
callback_len += 16; callback_len += 16;
/* XXX(nnorwitz): this leaks if realloc() fails. It also r = (atexit_callback**)PyMem_Realloc(atexit_callbacks,
doesn't verify realloc() returns a valid (non-NULL) pointer. */
atexit_callbacks = PyMem_Realloc(atexit_callbacks,
sizeof(atexit_callback*) * callback_len); sizeof(atexit_callback*) * callback_len);
if (r == NULL)
return PyErr_NoMemory();
atexit_callbacks = r;
} }
if (PyTuple_GET_SIZE(args) == 0) { if (PyTuple_GET_SIZE(args) == 0) {
...@@ -217,8 +228,8 @@ initatexit(void) ...@@ -217,8 +228,8 @@ initatexit(void)
if (m == NULL) if (m == NULL)
return; return;
/* XXX(nnorwitz): probably best to register a callback that will free
atexit_callbacks, otherwise valgrind will report memory leaks.
Need to call atexit_clear() first. */
_Py_PyAtExit(atexit_callfuncs); _Py_PyAtExit(atexit_callfuncs);
/* Register a callback that will free
atexit_callbacks, otherwise valgrind will report memory leaks. */
Py_AtExit(atexit_cleanup);
} }
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