Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bbe46d6

Browse files
committed
Issue #12483: ctypes: Fix a crash when the destruction of a callback
object triggers the garbage collector.
1 parent 1d7deaf commit bbe46d6

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

Lib/ctypes/test/test_callbacks.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ def __init__(self):
134134
if isinstance(x, X)]
135135
self.assertEqual(len(live), 0)
136136

137+
def test_issue12483(self):
138+
import gc
139+
class Nasty:
140+
def __del__(self):
141+
gc.collect()
142+
CFUNCTYPE(None)(lambda x=Nasty(): None)
143+
144+
137145
try:
138146
WINFUNCTYPE
139147
except NameError:

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ Tests
6565
Extension Modules
6666
-----------------
6767

68+
- Issue #12483: ctypes: Fix a crash when the destruction of a callback
69+
object triggers the garbage collector.
70+
6871
- Issue #12950: Fix passing file descriptors in multiprocessing, under
6972
OpenIndiana/Illumos.
7073

Modules/_ctypes/callbacks.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ static void
1313
CThunkObject_dealloc(PyObject *_self)
1414
{
1515
CThunkObject *self = (CThunkObject *)_self;
16+
PyObject_GC_UnTrack(self);
1617
Py_XDECREF(self->converters);
1718
Py_XDECREF(self->callable);
1819
Py_XDECREF(self->restype);

0 commit comments

Comments
 (0)