diff --git a/kqueue.c b/kqueue.c index 33476611..ee740eec 100644 --- a/kqueue.c +++ b/kqueue.c @@ -63,6 +63,7 @@ #include "event.h" #include "event-internal.h" #include "log.h" +#include "evsignal.h" #define EVLIST_X_KQINKERNEL 0x1000 @@ -440,12 +441,15 @@ kq_dealloc(struct event_base *base, void *arg) { struct kqop *kqop = arg; + evsignal_dealloc(base); + if (kqop->changes) free(kqop->changes); if (kqop->events) free(kqop->events); if (kqop->kq >= 0 && kqop->pid == getpid()) close(kqop->kq); + memset(kqop, 0, sizeof(struct kqop)); free(kqop); } diff --git a/signal.c b/signal.c index 74fa23f6..4371b703 100644 --- a/signal.c +++ b/signal.c @@ -346,12 +346,19 @@ evsignal_dealloc(struct event_base *base) _evsignal_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 evsignal_del() */ - free(base->sig.sh_old); + /* per index frees are handled in evsig_del() */ + if (base->sig.sh_old) { + free(base->sig.sh_old); + base->sig.sh_old = NULL; + } }