]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl-edit: don't leak the old value of contents
authorDavid Tardon <dtardon@redhat.com>
Wed, 17 Mar 2021 13:42:06 +0000 (14:42 +0100)
committerDavid Tardon <dtardon@redhat.com>
Thu, 18 Mar 2021 08:41:49 +0000 (09:41 +0100)
src/systemctl/systemctl-edit.c

index 4186ec3aea76cd7822d2754c1a07c0d87344b9a5..6a43b12d578ef7c17d9a28228996302dfa16e8fe 100644 (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);
                         }
                 }