diff options
author | Armin Rigo <arigo@tunes.org> | 2020-10-14 11:13:38 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2020-10-14 11:13:38 +0200 |
commit | c6c5b0d848b02aaf8d3e43d8cc191f53a1e9664e (patch) | |
tree | 39343932024e3eb7c8b6e5ba269bbc5f306645c9 | |
parent | 751f5adef7bd714b0e453d6d0d678177e8eb727f (diff) | |
download | cffi-c6c5b0d848b02aaf8d3e43d8cc191f53a1e9664e.tar.gz |
Issue #475
Fix a crash that can occur only if there is an error when building a callback
(in very rare cases), or in debug mode.
-rw-r--r-- | c/_cffi_backend.c | 3 | ||||
-rw-r--r-- | c/test_c.py | 2 |
2 files changed, 3 insertions, 2 deletions
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c index ecf0c8f..c9919ab 100644 --- a/c/_cffi_backend.c +++ b/c/_cffi_backend.c @@ -6299,8 +6299,8 @@ static PyObject *b_callback(PyObject *self, PyObject *args) cd->head.c_type = ct; cd->head.c_data = (char *)closure_exec; cd->head.c_weakreflist = NULL; + closure->user_data = NULL; cd->closure = closure; - PyObject_GC_Track(cd); cif_descr = (cif_description_t *)ct->ct_extra; if (cif_descr == NULL) { @@ -6357,6 +6357,7 @@ static PyObject *b_callback(PyObject *self, PyObject *args) "different from the 'ffi.h' file seen at compile-time)"); goto error; } + PyObject_GC_Track(cd); return (PyObject *)cd; error: diff --git a/c/test_c.py b/c/test_c.py index 643cc90..bb6b586 100644 --- a/c/test_c.py +++ b/c/test_c.py @@ -1470,7 +1470,7 @@ def test_a_lot_of_callbacks(): def make_callback(m): def cb(n): return n + m - return callback(BFunc, cb, 42) # 'cb' and 'BFunc' go out of scope + return callback(BFunc, cb, 42) # 'cb' goes out of scope # flist = [make_callback(i) for i in range(BIGNUM)] for i, f in enumerate(flist): |