diff options
author | David Tardon <dtardon@redhat.com> | 2021-03-17 14:42:06 +0100 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2021-03-18 09:41:49 +0100 |
commit | 8f3e1b9d015addda9a03cb647164318be3a5d9bd (patch) | |
tree | e2dddf9a9d4ca53d9ba05f2cc7a6085c05b69536 /src/systemctl/systemctl-edit.c | |
parent | journal-upload: use _cleanup_ for curl_slist (diff) | |
download | systemd-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.c | 8 |
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); } } |