]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-login: fix memory leak 16997/head
authorLennart Poettering <lennart@poettering.net>
Wed, 9 Sep 2020 17:38:04 +0000 (19:38 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 9 Sep 2020 18:14:30 +0000 (20:14 +0200)
Fixes: CID1432652
src/libsystemd/sd-login/sd-login.c

index 601a27ab570b9ad8b3de968831638f3143996151..d8baa6f8af527900b4e658cde67e390885fcebe7 100644 (file)
@@ -916,14 +916,14 @@ _public_ int sd_machine_get_ifindices(const char *machine, int **ret_ifindices)
         if (!tt)
                 return -ENOMEM;
 
-        size_t n = 0;
-        int *ifindices;
+        _cleanup_free_ int *ifindices = NULL;
         if (ret_ifindices) {
                 ifindices = new(int, strv_length(tt));
                 if (!ifindices)
                         return -ENOMEM;
         }
 
+        size_t n = 0;
         for (size_t i = 0; tt[i]; i++) {
                 int ind;
 
@@ -938,7 +938,8 @@ _public_ int sd_machine_get_ifindices(const char *machine, int **ret_ifindices)
         }
 
         if (ret_ifindices)
-                *ret_ifindices = ifindices;
+                *ret_ifindices = TAKE_PTR(ifindices);
+
         return n;
 }