Skip to content

Commit 1d73fc4

Browse files
committed
Fix a segfault in UDP handle
1 parent 486f82d commit 1d73fc4

File tree

4 files changed

+5
-18
lines changed

4 files changed

+5
-18
lines changed

uvloop/handles/handle.pxd

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ cdef class UVHandle:
2424

2525
cdef _warn_unclosed(self)
2626

27-
cdef _dealloc_impl(self)
2827
cdef _free(self)
2928
cdef _close(self)
3029

uvloop/handles/handle.pyx

-6
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ cdef class UVHandle:
2626
self.__class__.__name__))
2727

2828
def __dealloc__(self):
29-
self._dealloc_impl()
30-
31-
cdef _dealloc_impl(self):
3229
if UVLOOP_DEBUG:
3330
if self._loop is not None:
3431
self._loop._debug_handles_current.subtract([
@@ -40,9 +37,6 @@ cdef class UVHandle:
4037
.format(self.__class__.__name__))
4138

4239
if self._handle is NULL:
43-
if UVLOOP_DEBUG:
44-
if self._has_handle == 0:
45-
self._loop._debug_uv_handles_freed += 1
4640
return
4741

4842
# -> When we're at this point, something is wrong <-

uvloop/handles/process.pyx

+1-3
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ cdef class UVProcess(UVHandle):
190190
'UVProcess._close_after_spawn called after uv_spawn')
191191
self._fds_to_close.add(fd)
192192

193-
cdef _dealloc_impl(self):
193+
def __dealloc__(self):
194194
if self.uv_opt_env is not NULL:
195195
PyMem_RawFree(self.uv_opt_env)
196196
self.uv_opt_env = NULL
@@ -199,8 +199,6 @@ cdef class UVProcess(UVHandle):
199199
PyMem_RawFree(self.uv_opt_args)
200200
self.uv_opt_args = NULL
201201

202-
UVHandle._dealloc_impl(self)
203-
204202
cdef char** __to_cstring_array(self, list arr):
205203
cdef:
206204
int i

uvloop/handles/udp.pyx

+4-8
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,14 @@ cdef class UDPTransport(UVBaseTransport):
100100
udp._init(loop, sock, r_addr)
101101
return udp
102102

103-
cdef _dealloc_impl(self):
103+
def __dealloc__(self):
104+
if UVLOOP_DEBUG:
105+
self._loop._debug_uv_handles_freed += 1
106+
104107
if self._closed == 0:
105108
self._warn_unclosed()
106109
self._close()
107110

108-
# It is unsafe to call `self.poll._close()` here as
109-
# we might be at the stage where all CPython objects
110-
# are being freed, and `self.poll` points to some
111-
# zombie Python object. So we do nothing.
112-
113-
UVHandle._dealloc_impl(self)
114-
115111
cdef _free(self):
116112
if self.poll is not None:
117113
self.poll._close()

0 commit comments

Comments
 (0)