From: Nick Mathewson Date: Sat, 21 Nov 2009 06:11:49 +0000 (-0500) Subject: Fix memory-leak of signal handler array with kqueue. X-Git-Tag: release-2.0.4-alpha~138 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e1ffbb82e34d786d07a5acdb16077f6526f610c3;p=libevent Fix memory-leak of signal handler array with kqueue. It turns out that kqueue_dealloc wasn't calling evsig_dealloc() (because it doesn't use the main signal handler logic) so the sh_old array was leaking. This patch also introduces a fix in evsig_dealloc() where we set the sh_old array to NULL when we free it, so that main/fork can pass. --- diff --git a/kqueue.c b/kqueue.c index 3de41bbc..8cb7824e 100644 --- a/kqueue.c +++ b/kqueue.c @@ -404,6 +404,7 @@ static void kq_dealloc(struct event_base *base) { struct kqop *kqop = base->evbase; + evsig_dealloc(base); kqop_free(kqop); } diff --git a/signal.c b/signal.c index 3cf45f2b..b0bde815 100644 --- a/signal.c +++ b/signal.c @@ -334,13 +334,19 @@ evsig_dealloc(struct event_base *base) _evsig_restore_handler(base, i); } - EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[0]); - base->sig.ev_signal_pair[0] = -1; - EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[1]); - base->sig.ev_signal_pair[1] = -1; + if (base->sig.ev_signal_pair[0] != -1) { + EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[0]); + base->sig.ev_signal_pair[0] = -1; + } + if (base->sig.ev_signal_pair[1] != -1) { + EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[1]); + base->sig.ev_signal_pair[1] = -1; + } base->sig.sh_old_max = 0; /* per index frees are handled in evsig_del() */ - if (base->sig.sh_old) + if (base->sig.sh_old) { mm_free(base->sig.sh_old); + base->sig.sh_old = NULL; + } }