From 77c0e84f2403278177ada66a7c0dfccc61c851c2 Mon Sep 17 00:00:00 2001 From: Arman Uguray Date: Wed, 13 Aug 2014 19:27:54 -0700 Subject: [PATCH] shared/io-mainloop: Increment the ref count inside io_callback. Incrementing the reference count before invoking the event handlers and decrementing it thereafter allows io_destroy to be safely called from within the event callbacks. This patch achieves that. --- src/shared/io-mainloop.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/shared/io-mainloop.c b/src/shared/io-mainloop.c index 3e33d88db..1563ce57c 100644 --- a/src/shared/io-mainloop.c +++ b/src/shared/io-mainloop.c @@ -92,12 +92,15 @@ static void io_callback(int fd, uint32_t events, void *user_data) { struct io *io = user_data; + io_ref(io); + if ((events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR))) { io->read_callback = NULL; io->write_callback = NULL; if (!io->disconnect_callback) { mainloop_remove_fd(io->fd); + io_unref(io); return; } @@ -144,6 +147,8 @@ static void io_callback(int fd, uint32_t events, void *user_data) mainloop_modify_fd(io->fd, io->events); } } + + io_unref(io); } struct io *io_new(int fd) -- 2.47.3