Skip to content

Commit 53bb400

Browse files
committed
Avoid call to PyNumber_InPlaceSubtract by casting to size_t in free
1 parent 0dd50c6 commit 53bb400

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

cymem/cymem.pyx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@ cdef class Pool:
141141
# We need a critical section on both self and self.addresses here.
142142
# See comment in alloc for rationale.
143143
with cython.critical_section(self, self.addresses):
144-
self.size -= self.addresses.pop(<size_t>p)
144+
# The cast to size_t below is needed so that Cython
145+
# does not call into the C API to do the subtraction,
146+
# which could potentially release the critical section.
147+
self.size -= <size_t>self.addresses.pop(<size_t>p)
145148
self.pyfree.free(p)
146149

147150
def own_pyref(self, object py_ref):

0 commit comments

Comments
 (0)