1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-22 22:03:43 +03:00

sd-event: fix memleak when built without assertion

Fixes a bug introduced by baf3fdec27f0b3a1f3d39c7def2a778824cbee51.

This also adds several assertions at the beginning of the function.

Fixes #34899.

(cherry picked from commit 5dc0668802cd07cdca2dc5bda52cc1e63b57f145)
(cherry picked from commit 7455e7622113969866ed116d101aa54cfe2b1f7e)
This commit is contained in:
Yu Watanabe 2024-10-26 03:25:26 +09:00 committed by Luca Boccassi
parent 0a1715feb6
commit 261469e369

View File

@ -5219,6 +5219,9 @@ _public_ int sd_event_set_signal_exit(sd_event *e, int b) {
int r;
assert_return(e, -EINVAL);
assert_return(e = event_resolve(e), -ENOPKG);
assert_return(e->state != SD_EVENT_FINISHED, -ESTALE);
assert_return(!event_origin_changed(e), -ECHILD);
if (b) {
/* We want to maintain pointers to these event sources, so that we can destroy them when told
@ -5230,7 +5233,7 @@ _public_ int sd_event_set_signal_exit(sd_event *e, int b) {
if (r < 0)
return r;
assert(sd_event_source_set_floating(e->sigint_event_source, true) >= 0);
assert_se(sd_event_source_set_floating(e->sigint_event_source, true) >= 0);
change = true;
}
@ -5238,26 +5241,26 @@ _public_ int sd_event_set_signal_exit(sd_event *e, int b) {
r = sd_event_add_signal(e, &e->sigterm_event_source, SIGTERM | SD_EVENT_SIGNAL_PROCMASK, NULL, NULL);
if (r < 0) {
if (change) {
assert(sd_event_source_set_floating(e->sigint_event_source, false) >= 0);
assert_se(sd_event_source_set_floating(e->sigint_event_source, false) >= 0);
e->sigint_event_source = sd_event_source_unref(e->sigint_event_source);
}
return r;
}
assert(sd_event_source_set_floating(e->sigterm_event_source, true) >= 0);
assert_se(sd_event_source_set_floating(e->sigterm_event_source, true) >= 0);
change = true;
}
} else {
if (e->sigint_event_source) {
assert(sd_event_source_set_floating(e->sigint_event_source, false) >= 0);
assert_se(sd_event_source_set_floating(e->sigint_event_source, false) >= 0);
e->sigint_event_source = sd_event_source_unref(e->sigint_event_source);
change = true;
}
if (e->sigterm_event_source) {
assert(sd_event_source_set_floating(e->sigterm_event_source, false) >= 0);
assert_se(sd_event_source_set_floating(e->sigterm_event_source, false) >= 0);
e->sigterm_event_source = sd_event_source_unref(e->sigterm_event_source);
change = true;
}