chiark / gitweb /
sd-login: fix memleak when output argument is NULL
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 8 Jul 2017 22:04:44 +0000 (18:04 -0400)
committerSven Eden <yamakuzure@gmx.net>
Tue, 25 Jul 2017 07:46:53 +0000 (09:46 +0200)
src/libelogind/sd-login/sd-login.c

index 5f90ba70c4121ab13fdec1077ee974b9caffab4f..80b8f8fefc7f91f1a817d2936655d51e1dc998ab 100644 (file)
@@ -942,7 +942,8 @@ _public_ int sd_get_uids(uid_t **users) {
 }
 
 _public_ int sd_get_machine_names(char ***machines) {
 }
 
 _public_ int sd_get_machine_names(char ***machines) {
-        char **l, **a, **b;
+        _cleanup_strv_free_ char **l = NULL;
+        char **a, **b;
         int r;
 
         r = get_files_in_directory("/run/systemd/machines/", &l);
         int r;
 
         r = get_files_in_directory("/run/systemd/machines/", &l);
@@ -971,8 +972,10 @@ _public_ int sd_get_machine_names(char ***machines) {
                 *b = NULL;
         }
 
                 *b = NULL;
         }
 
-        if (machines)
+        if (machines) {
                 *machines = l;
                 *machines = l;
+                l = NULL;
+        }
         return r;
 }
 
         return r;
 }