mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-09 12:28:19 -04:00
Fix memory-leak of signal handler array with kqueue. [backport]
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:
parent
5b10d008e9
commit
01f3775b37
4
kqueue.c
4
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);
|
||||
}
|
||||
|
19
signal.c
19
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user