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.
This commit is contained in:
Nick Mathewson 2009-11-21 01:11:49 -05:00
parent 07e9e9b4b1
commit e1ffbb82e3
2 changed files with 12 additions and 5 deletions

View File

@ -404,6 +404,7 @@ static void
kq_dealloc(struct event_base *base)
{
struct kqop *kqop = base->evbase;
evsig_dealloc(base);
kqop_free(kqop);
}

View File

@ -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;
}
}