Blame SOURCES/0317-core-fix-memory-leak-on-failed-preset-all.patch

17b0f1
From 9d00fbb87c43e129e1ab29298afc86b7e8eed25c Mon Sep 17 00:00:00 2001
17b0f1
From: Evgeny Vereshchagin <evvers@ya.ru>
17b0f1
Date: Mon, 18 Jan 2016 06:10:33 +0000
17b0f1
Subject: [PATCH] core: fix memory leak on failed preset-all
17b0f1
17b0f1
How to reproduce
17b0f1
$ systemctl set-default multi-user # https://github.com/systemd/systemd/issues/2298
17b0f1
$ systemctl preset-all
17b0f1
Failed to execute operation: Too many levels of symbolic links
17b0f1
17b0f1
$ systemctl poweroff
17b0f1
17b0f1
Fixes:
17b0f1
==1==
17b0f1
==1== HEAP SUMMARY:
17b0f1
==1==     in use at exit: 65,645 bytes in 7 blocks
17b0f1
==1==   total heap usage: 40,539 allocs, 40,532 frees, 30,147,547 bytes allocated
17b0f1
==1==
17b0f1
==1== 109 (24 direct, 85 indirect) bytes in 1 blocks are definitely lost in loss record 2 of 7
17b0f1
==1==    at 0x4C2BBCF: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
17b0f1
==1==    by 0x4C2DE2F: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
17b0f1
==1==    by 0x23DA71: unit_file_changes_add (install.c:233)
17b0f1
==1==    by 0x23E45D: remove_marked_symlinks_fd (install.c:453)
17b0f1
==1==    by 0x23E267: remove_marked_symlinks_fd (install.c:405)
17b0f1
==1==    by 0x23E641: remove_marked_symlinks (install.c:494)
17b0f1
==1==    by 0x243A91: execute_preset (install.c:2190)
17b0f1
==1==    by 0x244343: unit_file_preset_all (install.c:2351)
17b0f1
==1==    by 0x18AAA2: method_preset_all_unit_files (dbus-manager.c:1846)
17b0f1
==1==    by 0x1D8157: method_callbacks_run (bus-objects.c:420)
17b0f1
==1==    by 0x1DA9E9: object_find_and_run (bus-objects.c:1257)
17b0f1
==1==    by 0x1DB02B: bus_process_object (bus-objects.c:1373)
17b0f1
==1==
17b0f1
==1== LEAK SUMMARY:
17b0f1
==1==    definitely lost: 24 bytes in 1 blocks
17b0f1
==1==    indirectly lost: 85 bytes in 1 blocks
17b0f1
==1==      possibly lost: 0 bytes in 0 blocks
17b0f1
==1==    still reachable: 65,536 bytes in 5 blocks
17b0f1
==1==         suppressed: 0 bytes in 0 blocks
17b0f1
==1== Reachable blocks (those to which a pointer was found) are not shown.
17b0f1
==1== To see them, rerun with: --leak-check=full --show-leak-kinds=all
17b0f1
==1==
17b0f1
==1== For counts of detected and suppressed errors, rerun with: -v
17b0f1
==1== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
17b0f1
17b0f1
Cherry-picked from: c292c3af38c8c23e183f3e63ef492926cea64bab
17b0f1
Related: #1331667
17b0f1
---
17b0f1
 src/core/dbus-manager.c | 4 +++-
17b0f1
 1 file changed, 3 insertions(+), 1 deletion(-)
17b0f1
17b0f1
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
17b0f1
index 1a5525e50f..9eef290ca7 100644
17b0f1
--- a/src/core/dbus-manager.c
17b0f1
+++ b/src/core/dbus-manager.c
17b0f1
@@ -1875,8 +1875,10 @@ static int method_preset_all_unit_files(sd_bus *bus, sd_bus_message *message, vo
17b0f1
         scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
17b0f1
 
17b0f1
         r = unit_file_preset_all(scope, runtime, NULL, mm, force, &changes, &n_changes);
17b0f1
-        if (r < 0)
17b0f1
+        if (r < 0) {
17b0f1
+                unit_file_changes_free(changes, n_changes);
17b0f1
                 return r;
17b0f1
+        }
17b0f1
 
17b0f1
         return reply_unit_file_changes_and_free(m, bus, message, -1, changes, n_changes);
17b0f1
 }