Skip to content

Commit 2af7b2a

Browse files
committed
Correctly dealloc detached handlers
This is a different fix for issue #37. The original fix that removed dynamic memory allocation of uv_handles had to be reverted.
1 parent 7b0b195 commit 2af7b2a

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

uvloop/handles/handle.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ cdef class UVHandle:
1717
cdef _error(self, exc, throw)
1818
cdef _fatal_error(self, exc, throw, reason=?)
1919

20-
cdef _free(self)
20+
cdef inline _free(self)
2121
cdef _close(self)
2222

2323

uvloop/handles/handle.pyx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ cdef class UVHandle:
7070
self._closed = 1
7171
self._free()
7272

73-
74-
cdef _free(self):
73+
cdef inline _free(self):
7574
PyMem_Free(self._handle)
7675
self._handle = NULL
7776

@@ -303,17 +302,17 @@ cdef void __uv_close_handle_cb(uv.uv_handle_t* handle) with gil:
303302
PyMem_Free(handle)
304303
return
305304

306-
if <object>handle.data is not __NOHANDLE__:
305+
if <object>handle.data is __NOHANDLE__:
306+
# The original UVHandle is long dead. Just free the mem of
307+
# the uv_handle_t* handler.
308+
PyMem_Free(handle)
309+
else:
307310
h = <UVHandle>handle.data
308-
h._handle = NULL
309311
IF DEBUG:
310312
h._loop._debug_handles_closed.update([
311313
h.__class__.__name__])
312314
h._free()
313315
Py_DECREF(h) # Was INCREFed in UVHandle._close
314-
return
315-
316-
PyMem_Free(handle)
317316

318317

319318
cdef void __close_all_handles(Loop loop):

uvloop/handles/process.pyx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ cdef class UVProcess(UVHandle):
177177
'UVProcess._close_after_spawn called after uv_spawn')
178178
self._fds_to_close.add(fd)
179179

180-
cdef _free(self):
180+
def __dealloc__(self):
181181
if self.uv_opt_env is not NULL:
182182
PyMem_Free(self.uv_opt_env)
183183
self.uv_opt_env = NULL
@@ -186,8 +186,6 @@ cdef class UVProcess(UVHandle):
186186
PyMem_Free(self.uv_opt_args)
187187
self.uv_opt_args = NULL
188188

189-
UVHandle._free(self)
190-
191189
cdef char** __to_cstring_array(self, list arr):
192190
cdef:
193191
int i

0 commit comments

Comments
 (0)