1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-19 22:50:17 +03:00

systemctl-edit: don't leak the old value of contents

This commit is contained in:
David Tardon 2021-03-17 14:42:06 +01:00
parent c4a2d475f1
commit 8f3e1b9d01

View File

@ -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);
}
}