From: Amaury Forgeot d'Arc Date: Mon, 12 Sep 2011 18:12:09 +0000 (+0200) Subject: Issue #12483: ctypes: Fix a crash when the destruction of a callback X-Git-Tag: v2.7.3rc1~456 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=439c25eb9e53fb5b47dd392cccd3a8183e0910eb;p=thirdparty%2FPython%2Fcpython.git Issue #12483: ctypes: Fix a crash when the destruction of a callback object triggers the garbage collector. --- diff --git a/Lib/ctypes/test/test_callbacks.py b/Lib/ctypes/test/test_callbacks.py index 621a0192b315..901456df19cc 100644 --- a/Lib/ctypes/test/test_callbacks.py +++ b/Lib/ctypes/test/test_callbacks.py @@ -140,6 +140,14 @@ class Callbacks(unittest.TestCase): if isinstance(x, X)] self.assertEqual(len(live), 0) + def test_issue12483(self): + import gc + class Nasty: + def __del__(self): + gc.collect() + CFUNCTYPE(None)(lambda x=Nasty(): None) + + try: WINFUNCTYPE except NameError: diff --git a/Misc/NEWS b/Misc/NEWS index 41328fd3e831..7984e174e9c6 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -192,6 +192,9 @@ Library Extension Modules ----------------- +- Issue #12483: ctypes: Fix a crash when the destruction of a callback + object triggers the garbage collector. + - Issue #12950: Fix passing file descriptors in multiprocessing, under OpenIndiana/Illumos. diff --git a/Modules/_ctypes/callbacks.c b/Modules/_ctypes/callbacks.c index 2b54a85b8f3c..47dbe05a5159 100644 --- a/Modules/_ctypes/callbacks.c +++ b/Modules/_ctypes/callbacks.c @@ -18,6 +18,7 @@ static void CThunkObject_dealloc(PyObject *_self) { CThunkObject *self = (CThunkObject *)_self; + PyObject_GC_UnTrack(self); Py_XDECREF(self->converters); Py_XDECREF(self->callable); Py_XDECREF(self->restype);