Skip to content

Commit

Permalink
Merge pull request #259 from p4l1ly/memleak_fix
Browse files Browse the repository at this point in the history
memory leak fix: _SegmentArrayMessageReader: release each view
  • Loading branch information
haata authored May 13, 2021
2 parents 73e83c9 + c010966 commit 581332f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions capnp/lib/capnp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4136,6 +4136,7 @@ cdef class _FlatArrayMessageReader(_MessageReader):
cdef class _SegmentArrayMessageReader(_MessageReader):

cdef object _objects_to_pin
cdef uint num_segments
cdef schema_cpp.ConstWordArrayPtr* _seg_ptrs
cdef Py_buffer* views

Expand All @@ -4146,6 +4147,7 @@ cdef class _SegmentArrayMessageReader(_MessageReader):
cdef schema_cpp.ConstWordArrayPtr seg_ptr
self._seg_ptrs = <schema_cpp.ConstWordArrayPtr*>malloc(num_segments * sizeof(schema_cpp.ConstWordArrayPtr))
self.views = <Py_buffer*>malloc(num_segments * sizeof(Py_buffer))
self.num_segments = num_segments
self._objects_to_pin = []
for i in range(0, num_segments):
if PyObject_GetBuffer(segments[i], &self.views[i], PyBUF_SIMPLE) != 0:
Expand All @@ -4165,6 +4167,8 @@ cdef class _SegmentArrayMessageReader(_MessageReader):

def __dealloc__(self):
free(self._seg_ptrs)
for i in range(0, self.num_segments):
PyBuffer_Release(&self.views[i])
free(self.views)
del self.thisptr

Expand Down

0 comments on commit 581332f

Please sign in to comment.