|
|
8d419f |
From d35c27e44abcde252abddf369762dee8da309903 Mon Sep 17 00:00:00 2001
|
|
|
8d419f |
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
|
|
8d419f |
Date: Tue, 10 May 2022 14:09:24 +0900
|
|
|
8d419f |
Subject: [PATCH] core/timer: fix memleak
|
|
|
8d419f |
|
|
|
8d419f |
Fixes #23326.
|
|
|
8d419f |
|
|
|
8d419f |
(cherry picked from commit d3ab7b8078944db28bc621f43dd942a3c878fffb)
|
|
|
8d419f |
Related: #2087652
|
|
|
8d419f |
---
|
|
|
8d419f |
src/core/timer.c | 11 ++++++-----
|
|
|
8d419f |
1 file changed, 6 insertions(+), 5 deletions(-)
|
|
|
8d419f |
|
|
|
8d419f |
diff --git a/src/core/timer.c b/src/core/timer.c
|
|
|
8d419f |
index a13b864741..0dc49dd46b 100644
|
|
|
8d419f |
--- a/src/core/timer.c
|
|
|
8d419f |
+++ b/src/core/timer.c
|
|
|
8d419f |
@@ -135,6 +135,7 @@ static int timer_add_trigger_dependencies(Timer *t) {
|
|
|
8d419f |
}
|
|
|
8d419f |
|
|
|
8d419f |
static int timer_setup_persistent(Timer *t) {
|
|
|
8d419f |
+ _cleanup_free_ char *stamp_path = NULL;
|
|
|
8d419f |
int r;
|
|
|
8d419f |
|
|
|
8d419f |
assert(t);
|
|
|
8d419f |
@@ -148,13 +149,13 @@ static int timer_setup_persistent(Timer *t) {
|
|
|
8d419f |
if (r < 0)
|
|
|
8d419f |
return r;
|
|
|
8d419f |
|
|
|
8d419f |
- t->stamp_path = strjoin("/var/lib/systemd/timers/stamp-", UNIT(t)->id);
|
|
|
8d419f |
+ stamp_path = strjoin("/var/lib/systemd/timers/stamp-", UNIT(t)->id);
|
|
|
8d419f |
} else {
|
|
|
8d419f |
const char *e;
|
|
|
8d419f |
|
|
|
8d419f |
e = getenv("XDG_DATA_HOME");
|
|
|
8d419f |
if (e)
|
|
|
8d419f |
- t->stamp_path = strjoin(e, "/systemd/timers/stamp-", UNIT(t)->id);
|
|
|
8d419f |
+ stamp_path = strjoin(e, "/systemd/timers/stamp-", UNIT(t)->id);
|
|
|
8d419f |
else {
|
|
|
8d419f |
|
|
|
8d419f |
_cleanup_free_ char *h = NULL;
|
|
|
8d419f |
@@ -163,14 +164,14 @@ static int timer_setup_persistent(Timer *t) {
|
|
|
8d419f |
if (r < 0)
|
|
|
8d419f |
return log_unit_error_errno(UNIT(t), r, "Failed to determine home directory: %m");
|
|
|
8d419f |
|
|
|
8d419f |
- t->stamp_path = strjoin(h, "/.local/share/systemd/timers/stamp-", UNIT(t)->id);
|
|
|
8d419f |
+ stamp_path = strjoin(h, "/.local/share/systemd/timers/stamp-", UNIT(t)->id);
|
|
|
8d419f |
}
|
|
|
8d419f |
}
|
|
|
8d419f |
|
|
|
8d419f |
- if (!t->stamp_path)
|
|
|
8d419f |
+ if (!stamp_path)
|
|
|
8d419f |
return log_oom();
|
|
|
8d419f |
|
|
|
8d419f |
- return 0;
|
|
|
8d419f |
+ return free_and_replace(t->stamp_path, stamp_path);
|
|
|
8d419f |
}
|
|
|
8d419f |
|
|
|
8d419f |
static uint64_t timer_get_fixed_delay_hash(Timer *t) {
|