Skip to content

Commit

Permalink
Correctly dealloc detached handlers
Browse files Browse the repository at this point in the history
This is a different fix for issue #37. The original fix that removed
dynamic memory allocation of uv_handles had to be reverted.
  • Loading branch information
1st1 committed Jul 12, 2016
1 parent 7b0b195 commit 2af7b2a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion uvloop/handles/handle.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cdef class UVHandle:
cdef _error(self, exc, throw)
cdef _fatal_error(self, exc, throw, reason=?)

cdef _free(self)
cdef inline _free(self)
cdef _close(self)


Expand Down
13 changes: 6 additions & 7 deletions uvloop/handles/handle.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ cdef class UVHandle:
self._closed = 1
self._free()


cdef _free(self):
cdef inline _free(self):
PyMem_Free(self._handle)
self._handle = NULL

Expand Down Expand Up @@ -303,17 +302,17 @@ cdef void __uv_close_handle_cb(uv.uv_handle_t* handle) with gil:
PyMem_Free(handle)
return

if <object>handle.data is not __NOHANDLE__:
if <object>handle.data is __NOHANDLE__:
# The original UVHandle is long dead. Just free the mem of
# the uv_handle_t* handler.
PyMem_Free(handle)
else:
h = <UVHandle>handle.data
h._handle = NULL
IF DEBUG:
h._loop._debug_handles_closed.update([
h.__class__.__name__])
h._free()
Py_DECREF(h) # Was INCREFed in UVHandle._close
return

PyMem_Free(handle)


cdef void __close_all_handles(Loop loop):
Expand Down
4 changes: 1 addition & 3 deletions uvloop/handles/process.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ cdef class UVProcess(UVHandle):
'UVProcess._close_after_spawn called after uv_spawn')
self._fds_to_close.add(fd)

cdef _free(self):
def __dealloc__(self):
if self.uv_opt_env is not NULL:
PyMem_Free(self.uv_opt_env)
self.uv_opt_env = NULL
Expand All @@ -186,8 +186,6 @@ cdef class UVProcess(UVHandle):
PyMem_Free(self.uv_opt_args)
self.uv_opt_args = NULL

UVHandle._free(self)

cdef char** __to_cstring_array(self, list arr):
cdef:
int i
Expand Down

0 comments on commit 2af7b2a

Please sign in to comment.