]> granicus.if.org Git - libevent/commitdiff
Fix memory-leak of signal handler array with kqueue.
authorNick Mathewson <nickm@torproject.org>
Sat, 21 Nov 2009 06:11:49 +0000 (01:11 -0500)
committerNick Mathewson <nickm@torproject.org>
Sun, 22 Nov 2009 04:57:44 +0000 (23:57 -0500)
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.

kqueue.c
signal.c

index 3de41bbc9a4e8e7604447331b73788944290c90e..8cb7824ea8512bab58e5272870221be787ebd05b 100644 (file)
--- 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);
 }
 
index 3cf45f2b3c3cabe9f5ec63df502a96374cd6b15f..b0bde8155098a3993357b04ceaa7d52760738cbb 100644 (file)
--- 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;
+       }
 }