diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-05-10 14:09:24 +0900 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-05-10 13:50:50 +0200 |
commit | d3ab7b8078944db28bc621f43dd942a3c878fffb (patch) | |
tree | 8b62f8669be904e1f98474063dc4fb668afaeb91 /src/core/timer.c | |
parent | 16f74783d888117bc9ddc8b54138acbf730c4584 (diff) | |
download | systemd-d3ab7b8078944db28bc621f43dd942a3c878fffb.tar.gz |
core/timer: fix memleak
Fixes #23326.
Diffstat (limited to 'src/core/timer.c')
-rw-r--r-- | src/core/timer.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/core/timer.c b/src/core/timer.c index ab107860a7..17663a175b 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -132,6 +132,7 @@ static int timer_add_trigger_dependencies(Timer *t) { } static int timer_setup_persistent(Timer *t) { + _cleanup_free_ char *stamp_path = NULL; int r; assert(t); @@ -145,13 +146,13 @@ static int timer_setup_persistent(Timer *t) { if (r < 0) return r; - t->stamp_path = strjoin("/var/lib/systemd/timers/stamp-", UNIT(t)->id); + stamp_path = strjoin("/var/lib/systemd/timers/stamp-", UNIT(t)->id); } else { const char *e; e = getenv("XDG_DATA_HOME"); if (e) - t->stamp_path = strjoin(e, "/systemd/timers/stamp-", UNIT(t)->id); + stamp_path = strjoin(e, "/systemd/timers/stamp-", UNIT(t)->id); else { _cleanup_free_ char *h = NULL; @@ -160,14 +161,14 @@ static int timer_setup_persistent(Timer *t) { if (r < 0) return log_unit_error_errno(UNIT(t), r, "Failed to determine home directory: %m"); - t->stamp_path = strjoin(h, "/.local/share/systemd/timers/stamp-", UNIT(t)->id); + stamp_path = strjoin(h, "/.local/share/systemd/timers/stamp-", UNIT(t)->id); } } - if (!t->stamp_path) + if (!stamp_path) return log_oom(); - return 0; + return free_and_replace(t->stamp_path, stamp_path); } static uint64_t timer_get_fixed_delay_hash(Timer *t) { |