Skip to content

Commit

Permalink
Fix a segfault in UDP handle
Browse files Browse the repository at this point in the history
  • Loading branch information
1st1 committed Aug 1, 2018
1 parent 486f82d commit 5a44383
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
1 change: 0 additions & 1 deletion uvloop/handles/handle.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ cdef class UVHandle:

cdef _warn_unclosed(self)

cdef _dealloc_impl(self)
cdef _free(self)
cdef _close(self)

Expand Down
6 changes: 0 additions & 6 deletions uvloop/handles/handle.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ cdef class UVHandle:
self.__class__.__name__))

def __dealloc__(self):
self._dealloc_impl()

cdef _dealloc_impl(self):
if UVLOOP_DEBUG:
if self._loop is not None:
self._loop._debug_handles_current.subtract([
Expand All @@ -40,9 +37,6 @@ cdef class UVHandle:
.format(self.__class__.__name__))

if self._handle is NULL:
if UVLOOP_DEBUG:
if self._has_handle == 0:
self._loop._debug_uv_handles_freed += 1
return

# -> When we're at this point, something is wrong <-
Expand Down
4 changes: 1 addition & 3 deletions uvloop/handles/process.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ cdef class UVProcess(UVHandle):
'UVProcess._close_after_spawn called after uv_spawn')
self._fds_to_close.add(fd)

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

UVHandle._dealloc_impl(self)

cdef char** __to_cstring_array(self, list arr):
cdef:
int i
Expand Down
16 changes: 8 additions & 8 deletions uvloop/handles/udp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,18 @@ cdef class UDPTransport(UVBaseTransport):
udp._init(loop, sock, r_addr)
return udp

cdef _dealloc_impl(self):
def __dealloc__(self):
# Cython has a weird bug when __dealloc__ is declared on
# the base class and calls some overloaded functions.
# So we duplicate __dealloc__ declaration here.

if UVLOOP_DEBUG:
self._loop._debug_uv_handles_freed += 1

if self._closed == 0:
self._warn_unclosed()
self._close()

# It is unsafe to call `self.poll._close()` here as
# we might be at the stage where all CPython objects
# are being freed, and `self.poll` points to some
# zombie Python object. So we do nothing.

UVHandle._dealloc_impl(self)

cdef _free(self):
if self.poll is not None:
self.poll._close()
Expand Down

0 comments on commit 5a44383

Please sign in to comment.