From: David Tardon Date: Wed, 17 Mar 2021 13:42:06 +0000 (+0100) Subject: systemctl-edit: don't leak the old value of contents X-Git-Tag: v248-2~53^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8f3e1b9d015addda9a03cb647164318be3a5d9bd;p=thirdparty%2Fsystemd.git systemctl-edit: don't leak the old value of contents --- diff --git a/src/systemctl/systemctl-edit.c b/src/systemctl/systemctl-edit.c index 4186ec3aea7..6a43b12d578 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); } }