923a60
From fa5a3a16e94773baf1dce3881d5cfab556b87113 Mon Sep 17 00:00:00 2001
923a60
From: =?UTF-8?q?Cristian=20Rodr=C3=ADguez?= <crrodriguez@opensuse.org>
923a60
Date: Mon, 11 May 2015 23:30:38 -0300
923a60
Subject: [PATCH] core: fix memory leak in manager_run_generators()
923a60
923a60
If systemd is built with GCC address sanitizer or leak sanitizer
923a60
the following memory leak ocurs:
923a60
923a60
May 12 02:02:46 linux.site systemd[326]: =================================================================
923a60
May 12 02:02:46 linux.site systemd[326]: ==326==ERROR: LeakSanitizer: detected memory leaks
923a60
May 12 02:02:46 linux.site systemd[326]: Direct leak of 101 byte(s) in 3 object(s) allocated from:
923a60
May 12 02:02:46 linux.site systemd[326]: #0 0x7fd1f504993f in strdup (/usr/lib64/libasan.so.2+0x6293f)
923a60
May 12 02:02:46 linux.site systemd[326]: #1 0x55d6ffac5336 in strv_new_ap src/shared/strv.c:163
923a60
May 12 02:02:46 linux.site systemd[326]: #2 0x55d6ffac56a9 in strv_new src/shared/strv.c:185
923a60
May 12 02:02:46 linux.site systemd[326]: #3 0x55d6ffa80272 in generator_paths src/shared/path-lookup.c:223
923a60
May 12 02:02:46 linux.site systemd[326]: #4 0x55d6ff9bdb0f in manager_run_generators src/core/manager.c:2828
923a60
May 12 02:02:46 linux.site systemd[326]: #5 0x55d6ff9b1a10 in manager_startup src/core/manager.c:1121
923a60
May 12 02:02:46 linux.site systemd[326]: #6 0x55d6ff9a78e3 in main src/core/main.c:1667
923a60
May 12 02:02:46 linux.site systemd[326]: #7 0x7fd1f394e8c4 in __libc_start_main (/lib64/libc.so.6+0x208c4)
923a60
May 12 02:02:46 linux.site systemd[326]: Direct leak of 29 byte(s) in 1 object(s) allocated from:
923a60
May 12 02:02:46 linux.site systemd[326]: #0 0x7fd1f504993f in strdup (/usr/lib64/libasan.so.2+0x6293f)
923a60
May 12 02:02:46 linux.site systemd[326]: #1 0x55d6ffac5288 in strv_new_ap src/shared/strv.c:152
923a60
May 12 02:02:46 linux.site systemd[326]: #2 0x55d6ffac56a9 in strv_new src/shared/strv.c:185
923a60
May 12 02:02:46 linux.site systemd[326]: #3 0x55d6ffa80272 in generator_paths src/shared/path-lookup.c:223
923a60
May 12 02:02:46 linux.site systemd[326]: #4 0x55d6ff9bdb0f in manager_run_generators src/core/manager.c:2828
923a60
May 12 02:02:46 linux.site systemd[326]: #5 0x55d6ff9b1a10 in manager_startup src/core/manager.c:1121
923a60
May 12 02:02:46 linux.site systemd[326]: #6 0x55d6ff9a78e3 in main src/core/main.c:1667
923a60
May 12 02:02:46 linux.site systemd[326]: #7 0x7fd1f394e8c4 in __libc_start_main (/lib64/libc.so.6+0x208c4)
923a60
May 12 02:02:46 linux.site systemd[326]: SUMMARY: AddressSanitizer: 130 byte(s) leaked in 4 allocation(s).
923a60
923a60
There is a leak due to the the use of cleanup_free instead
923a60
_cleanup_strv_free_
923a60
923a60
Cherry-picked from: f42348ace7feb2311593b8cf6c876856eecf256a
923a60
Related: #1331667
923a60
---
923a60
 src/core/manager.c | 2 +-
923a60
 1 file changed, 1 insertion(+), 1 deletion(-)
923a60
923a60
diff --git a/src/core/manager.c b/src/core/manager.c
923a60
index bb5050303c..a1504bf17b 100644
923a60
--- a/src/core/manager.c
923a60
+++ b/src/core/manager.c
923a60
@@ -2827,7 +2827,7 @@ static void trim_generator_dir(Manager *m, char **generator) {
923a60
 }
923a60
 
923a60
 static int manager_run_generators(Manager *m) {
923a60
-        _cleanup_free_ char **paths = NULL;
923a60
+        _cleanup_strv_free_ char **paths = NULL;
923a60
         const char *argv[5];
923a60
         char **path;
923a60
         int r;