]> granicus.if.org Git - libevent/commitdiff
Tweaked callbacks to prevent race condition (https://github.com/libevent/libevent...
authorJohn Ohl <john@collabriasoftware.com>
Mon, 27 Jan 2014 18:03:36 +0000 (13:03 -0500)
committerJohn Ohl <john@collabriasoftware.com>
Mon, 27 Jan 2014 18:03:36 +0000 (13:03 -0500)
event.c

diff --git a/event.c b/event.c
index c946cbf98a60a976175b5c3cb73e13d03ce5c4aa..b97f1dbfd276724a76ea9c6d6415f08d1dd41be0 100644 (file)
--- a/event.c
+++ b/event.c
@@ -1495,8 +1495,15 @@ event_persist_closure(struct event_base *base, struct event *ev)
                run_at.tv_usec |= usec_mask;
                event_add_nolock_(ev, &run_at, 1);
        }
-       EVBASE_RELEASE_LOCK(base, th_base_lock);
-       (*ev->ev_callback)(ev->ev_fd, ev->ev_res, ev->ev_arg);
+
+       // Get our callback before we release the lock
+       void (*evcb_callback)(evutil_socket_t, short, void *) = *ev->ev_callback;
+
+       // Release the lock
+       EVBASE_RELEASE_LOCK(base, th_base_lock);
+
+       // Execute the callback
+       (evcb_callback)(ev->ev_fd, ev->ev_res, ev->ev_arg);
 }
 
 /*