summaryrefslogtreecommitdiffstats
path: root/src/libsystemd
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-10-25 20:25:26 +0200
committerMike Yuan <me@yhndnzj.com>2024-10-26 17:21:34 +0200
commit5dc0668802cd07cdca2dc5bda52cc1e63b57f145 (patch)
tree11b1b85cccc880a524c70460f335e90e9b0a62fb /src/libsystemd
parentman: fix typo (diff)
downloadsystemd-5dc0668802cd07cdca2dc5bda52cc1e63b57f145.tar.xz
systemd-5dc0668802cd07cdca2dc5bda52cc1e63b57f145.zip
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.
Diffstat (limited to 'src/libsystemd')
-rw-r--r--src/libsystemd/sd-event/sd-event.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c
index a2fd0de9e9..f19f579b48 100644
--- a/src/libsystemd/sd-event/sd-event.c
+++ b/src/libsystemd/sd-event/sd-event.c
@@ -5258,6 +5258,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
@@ -5269,7 +5272,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;
}
@@ -5277,26 +5280,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;
}