Skip to content

Commit

Permalink
Issue 553
Browse files Browse the repository at this point in the history
Two missing calls to PyObject_GC_UnTrack()
  • Loading branch information
arigo committed Dec 4, 2022
1 parent 2ddc99c commit 15c4b71
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions c/_cffi_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -1938,6 +1938,7 @@ static void cdataowninggc_dealloc(CDataObject *cd)
static void cdatafrombuf_dealloc(CDataObject *cd)
{
Py_buffer *view = ((CDataObject_frombuf *)cd)->bufferview;
PyObject_GC_UnTrack(cd);
cdata_dealloc(cd);

PyBuffer_Release(view);
Expand Down Expand Up @@ -2043,6 +2044,7 @@ static void cdatagcp_dealloc(CDataObject_gcp *cd)
{
PyObject *destructor = cd->destructor;
PyObject *origobj = cd->origobj;
PyObject_GC_UnTrack(cd);
cdata_dealloc((CDataObject *)cd);

gcp_finalize(destructor, origobj);
Expand Down
18 changes: 18 additions & 0 deletions testing/cffi0/test_ffi_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,24 @@ def test_bogus_struct_containing_struct_containing_array_varsize(self):
assert p.bcd == 9999999
assert p.foo.data[3] != 78 # has been overwritten with 9999999

def test_issue553(self):
import gc, warnings
ffi = FFI(backend=self.Backend())
p = ffi.new("int *", 123)
with warnings.catch_warnings(record=True) as w:
ffi.gc(p, lambda x: None)
gc.collect()
assert w == []

def test_issue553_from_buffer(self):
import gc, warnings
ffi = FFI(backend=self.Backend())
buf = b"123"
with warnings.catch_warnings(record=True) as w:
ffi.from_buffer(buf)
gc.collect()
assert w == []


class TestBitfield:
def check(self, source, expected_ofs_y, expected_align, expected_size):
Expand Down

0 comments on commit 15c4b71

Please sign in to comment.