from trunk: restore signal handlers correctly when we deallocate the signal base

svn:r914
This commit is contained in:
Niels Provos 2008-07-19 23:41:33 +00:00
parent e11392387a
commit 21c562897d
2 changed files with 12 additions and 3 deletions

View File

@ -10,6 +10,7 @@ Changes in 1.4.6-stable:
o Deal with evbuffer_read() returning -1 on EINTR|EAGAIN; from Adam Langley. o Deal with evbuffer_read() returning -1 on EINTR|EAGAIN; from Adam Langley.
o Fix a bug in which the DNS server would incorrectly set the type of a cname reply to a. o Fix a bug in which the DNS server would incorrectly set the type of a cname reply to a.
o Fix a bug where setting the timeout on a bufferevent would take not effect if the event was already pending. o Fix a bug where setting the timeout on a bufferevent would take not effect if the event was already pending.
o Fix a memory leak when using signals for some event bases; reported by Alexander Drozdov.
Changes in 1.4.5-stable: Changes in 1.4.5-stable:
o Fix connection keep-alive behavior for HTTP/1.0 o Fix connection keep-alive behavior for HTTP/1.0

View File

@ -143,14 +143,19 @@ _evsignal_set_handler(struct event_base *base,
* a dynamic array is used to keep footprint on the low side. * a dynamic array is used to keep footprint on the low side.
*/ */
if (evsignal >= sig->sh_old_max) { if (evsignal >= sig->sh_old_max) {
int new_max = evsignal + 1;
event_debug(("%s: evsignal (%d) >= sh_old_max (%d), resizing", event_debug(("%s: evsignal (%d) >= sh_old_max (%d), resizing",
__func__, evsignal, sig->sh_old_max)); __func__, evsignal, sig->sh_old_max));
sig->sh_old_max = evsignal + 1; p = realloc(sig->sh_old, new_max * sizeof(*sig->sh_old));
p = realloc(sig->sh_old, sig->sh_old_max * sizeof *sig->sh_old);
if (p == NULL) { if (p == NULL) {
event_warn("realloc"); event_warn("realloc");
return (-1); return (-1);
} }
memset((char *)p + sig->sh_old_max * sizeof(*sig->sh_old),
0, (new_max - sig->sh_old_max) * sizeof(*sig->sh_old));
sig->sh_old_max = new_max;
sig->sh_old = p; sig->sh_old = p;
} }
@ -326,8 +331,11 @@ evsignal_dealloc(struct event_base *base)
event_del(&base->sig.ev_signal); event_del(&base->sig.ev_signal);
base->sig.ev_signal_added = 0; base->sig.ev_signal_added = 0;
} }
for (i = 0; i < NSIG; ++i) for (i = 0; i < NSIG; ++i) {
if (i < base->sig.sh_old_max && base->sig.sh_old[i] != NULL)
_evsignal_restore_handler(base, i);
assert(TAILQ_EMPTY(&base->sig.evsigevents[0])); assert(TAILQ_EMPTY(&base->sig.evsigevents[0]));
}
EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[0]); EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[0]);
base->sig.ev_signal_pair[0] = -1; base->sig.ev_signal_pair[0] = -1;