Commit ab179184 authored by Martin Pieuchot's avatar Martin Pieuchot Committed by Philip Withnall

Reorder operations in _kqsub_cancel() to prevent races.

Removing the event and closing the related file descriptor must be
done first to make sure the kqueue subsystem delete pending events.

The timeout must be disarmed before freeing the directory dependency
list otherwise it might populate it again.

https://bugzilla.gnome.org/show_bug.cgi?id=795193
parent 1217b1bc
Pipeline #9527 passed with stage
in 2 minutes and 13 seconds
......@@ -373,28 +373,28 @@ _kqsub_cancel (kqueue_sub *sub)
{
struct kevent ev;
if (sub->deps)
/* Remove the event and close the file descriptor to automatically
* delete pending events. */
if (sub->fd != -1)
{
dl_free (sub->deps);
sub->deps = NULL;
EV_SET (&ev, sub->fd, EVFILT_VNODE, EV_DELETE, NOTE_ALL, 0, sub);
if (kevent (kq_queue, &ev, 1, NULL, 0, NULL) == -1)
{
g_warning ("Unable to remove event for %s: %s", sub->filename, g_strerror (errno));
return FALSE;
}
close (sub->fd);
sub->fd = -1;
}
_km_remove (sub);
/* Only in the missing list? We're done! */
if (sub->fd == -1)
return TRUE;
EV_SET (&ev, sub->fd, EVFILT_VNODE, EV_DELETE, NOTE_ALL, 0, sub);
if (kevent (kq_queue, &ev, 1, NULL, 0, NULL) == -1)
if (sub->deps)
{
g_warning ("Unable to remove event for %s: %s", sub->filename, g_strerror (errno));
return FALSE;
dl_free (sub->deps);
sub->deps = NULL;
}
close (sub->fd);
sub->fd = -1;
return TRUE;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment