summaryrefslogtreecommitdiffstats
path: root/src/systemctl/systemctl-edit.c
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2021-03-17 14:42:06 +0100
committerDavid Tardon <dtardon@redhat.com>2021-03-18 09:41:49 +0100
commit8f3e1b9d015addda9a03cb647164318be3a5d9bd (patch)
treee2dddf9a9d4ca53d9ba05f2cc7a6085c05b69536 /src/systemctl/systemctl-edit.c
parentjournal-upload: use _cleanup_ for curl_slist (diff)
downloadsystemd-8f3e1b9d015addda9a03cb647164318be3a5d9bd.tar.xz
systemd-8f3e1b9d015addda9a03cb647164318be3a5d9bd.zip
systemctl-edit: don't leak the old value of contents
Diffstat (limited to 'src/systemctl/systemctl-edit.c')
-rw-r--r--src/systemctl/systemctl-edit.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/systemctl/systemctl-edit.c b/src/systemctl/systemctl-edit.c
index 4186ec3aea..6a43b12d57 100644
--- a/src/systemctl/systemctl-edit.c
+++ b/src/systemctl/systemctl-edit.c
@@ -188,10 +188,12 @@ static int create_edit_temp_file(const char *new_path, const char *original_path
fprintf(f, "\n\n### %s", *path);
if (!isempty(contents)) {
- contents = strreplace(strstrip(contents), "\n", "\n# ");
- if (!contents)
+ _cleanup_free_ char *commented_contents = NULL;
+
+ commented_contents = strreplace(strstrip(contents), "\n", "\n# ");
+ if (!commented_contents)
return log_oom();
- fprintf(f, "\n# %s", contents);
+ fprintf(f, "\n# %s", commented_contents);
}
}