Skip to content

Commit 2fa177e

Browse files
authored
picoev: bugfixes and UB mitigation (#18991)
1 parent 2266cce commit 2fa177e

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

vlib/picoev/picoev.v

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ fn (mut pv Picoev) del(fd int) int {
106106
}
107107

108108
if pv.update_events(fd, picoev.picoev_del) != 0 {
109-
target.loop_id = -1
110-
target.fd = 0
111109
return -1
112110
}
113111

@@ -149,15 +147,20 @@ fn (mut pv Picoev) set_timeout(fd int, secs int) {
149147
// timeout event
150148
[direct_array_access; inline]
151149
fn (mut pv Picoev) handle_timeout() {
150+
mut to_remove := []int{}
151+
152152
for fd, timeout in pv.timeouts {
153153
if timeout <= pv.loop.now {
154-
target := pv.file_descriptors[fd]
155-
assert target.loop_id == pv.loop.id
156-
157-
pv.timeouts.delete(fd)
158-
unsafe { target.cb(fd, picoev.picoev_timeout, &pv) }
154+
to_remove << fd
159155
}
160156
}
157+
158+
for fd in to_remove {
159+
target := pv.file_descriptors[fd]
160+
assert target.loop_id == pv.loop.id
161+
pv.timeouts.delete(fd)
162+
unsafe { target.cb(fd, picoev.picoev_timeout, &pv) }
163+
}
161164
}
162165

163166
// accept_callback accepts a new connection from `listen_fd` and adds it to the loop

0 commit comments

Comments
 (0)