[systemd-devel] [PATCH] systemctl: fix resource leak CID #1237747

Cristian Rodríguez crrodriguez at opensuse.org
Wed Sep 17 17:56:25 PDT 2014


..by simply moving the declaration of "unit" into the STRV_FOREACH
loop as suggested by Andreas.
---
 src/systemctl/systemctl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 88be871..9012128 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -4449,7 +4449,6 @@ static int show(sd_bus *bus, char **args) {
 }
 
 static int cat(sd_bus *bus, char **args) {
-        _cleanup_free_ char *unit = NULL;
         _cleanup_strv_free_ char **names = NULL;
         char **name;
         bool first = true;
@@ -4468,6 +4467,8 @@ static int cat(sd_bus *bus, char **args) {
                 _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
                 _cleanup_strv_free_ char **dropin_paths = NULL;
                 _cleanup_free_ char *fragment_path = NULL;
+                _cleanup_free_ char *unit = NULL;
+
                 char **path;
 
                 unit = unit_dbus_path_from_name(*name);
-- 
2.1.0



More information about the systemd-devel mailing list