From 56f0e73abb541149fd1203a2c2004eef469f980b Mon Sep 17 00:00:00 2001 From: Kevin Klues Date: Sun, 1 Jun 2014 10:59:13 -0700 Subject: [PATCH 1/1] Bug fix in grow function and race fix in dispatcher --- user/benchutil/alarm_dispatch.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/user/benchutil/alarm_dispatch.c b/user/benchutil/alarm_dispatch.c index ed70097..d34d5fb 100644 --- a/user/benchutil/alarm_dispatch.c +++ b/user/benchutil/alarm_dispatch.c @@ -27,7 +27,9 @@ static void dispatch_alarm(struct event_msg *ev_msg, unsigned int ev_type) if (ev_msg) { // There is a slight race here if you don't disable the alarm before // deregistering its handler. Make sure you do this properly. - dispatch.handlers[ev_msg->ev_arg2](ev_msg, ev_type); + handle_event_t handler = dispatch.handlers[ev_msg->ev_arg2]; + if (handler) + handler(ev_msg, ev_type); } } @@ -45,8 +47,9 @@ static void init_alarm_dispatch() static void __maybe_grow_handler_array(int index) { if (dispatch.length <= index) { - int new_size = dispatch.length + GROWTH_INC*(index/GROWTH_INC); - dispatch.handlers = realloc(dispatch.handlers, new_size); + int new_size = GROWTH_INC * (1 + index/GROWTH_INC); + dispatch.handlers = realloc(dispatch.handlers, + new_size * sizeof(handle_event_t)); for (int i=dispatch.length; i