Discussion:
[Python-3000-checkins] r66562 - python/branches/py3k/Modules/atexitmodule.c
skip.montanaro
2008-09-23 00:52:29 UTC
Permalink
Author: skip.montanaro
Date: Tue Sep 23 02:52:29 2008
New Revision: 66562

Log:
Fix for issue 3666 - atexit.register with bad inputs segfaults on exit.
Reviewed by Christian Heimes.


Modified:
python/branches/py3k/Modules/atexitmodule.c

Modified: python/branches/py3k/Modules/atexitmodule.c
==============================================================================
--- python/branches/py3k/Modules/atexitmodule.c (original)
+++ python/branches/py3k/Modules/atexitmodule.c Tue Sep 23 02:52:29 2008
@@ -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 @@

/* 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_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 @@
PyMem_Free(cb);
}

-void
+static void
atexit_cleanup(void)
{
PyObject *r = atexit_clear(NULL);
@@ -260,8 +264,5 @@
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;
}
Benjamin Peterson
2008-09-23 01:25:48 UTC
Permalink
On Mon, Sep 22, 2008 at 7:52 PM, skip.montanaro
Post by skip.montanaro
Author: skip.montanaro
Date: Tue Sep 23 02:52:29 2008
New Revision: 66562
Fix for issue 3666 - atexit.register with bad inputs segfaults on exit.
Reviewed by Christian Heimes.
Test?
--
Cheers,
Benjamin Peterson
"There's no place like 127.0.0.1."
skip
2008-09-23 02:57:54 UTC
Permalink
Post by skip.montanaro
Fix for issue 3666 - atexit.register with bad inputs segfaults on exit.
Reviewed by Christian Heimes.
Benjamin> Test?

How do you write a test case for broken code which causes a segfault?
To recap, executing this code:

import sys, atexit
atexit.register(lambda: 1, 0, 0, (x for x in (1,2)), 0, 0)
sys.exit()

crashes the interpreter. With the fix suggested by Christian that I checked
in it doesn't.

Skip
Benjamin Peterson
2008-09-23 03:00:02 UTC
Permalink
Post by skip
Post by skip.montanaro
Fix for issue 3666 - atexit.register with bad inputs segfaults on exit.
Reviewed by Christian Heimes.
Benjamin> Test?
How do you write a test case for broken code which causes a segfault?
import sys, atexit
atexit.register(lambda: 1, 0, 0, (x for x in (1,2)), 0, 0)
sys.exit()
crashes the interpreter. With the fix suggested by Christian that I checked
in it doesn't.
Well, should it raise a TypeError?
Post by skip
Skip
--
Cheers,
Benjamin Peterson
"There's no place like 127.0.0.1."
skip
2008-09-23 03:09:39 UTC
Permalink
Post by skip
import sys, atexit
atexit.register(lambda: 1, 0, 0, (x for x in (1,2)), 0, 0)
sys.exit()
crashes the interpreter. With the fix suggested by Christian that I
checked in it doesn't.
Benjamin> Well, should it raise a TypeError?

Yes, and the code already did that. That wasn't what I was fixing.
Perhaps the existing test cases were deficient in that regard, but that's a
different matter.

Skip

Loading...