]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Fix memory leak in list_active_containers
authorLiFeng <lifeng68@huawei.com>
Tue, 24 Apr 2018 19:10:15 +0000 (15:10 -0400)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 23 Aug 2018 20:56:08 +0000 (22:56 +0200)
Signed-off-by: LiFeng <lifeng68@huawei.com>
src/lxc/lxccontainer.c

index 2f37854ce12ada4a2f70e41e5da24c3739d50d8a..fcc8ca65efe5ace7d0b94d5e6df754ebd420f29e 100644 (file)
@@ -4669,32 +4669,49 @@ int list_active_containers(const char *lxcpath, char ***nret,
                        char *recvpath = lxc_cmd_get_lxcpath(p);
                        if (!recvpath)
                                continue;
-                       if (strncmp(lxcpath, recvpath, lxcpath_len) != 0)
+                       if (strncmp(lxcpath, recvpath, lxcpath_len) != 0) {
+                               free(recvpath);
                                continue;
+                       }
+                       free(recvpath);
                        p = lxc_cmd_get_name(p);
                        if (!p)
                                continue;
                }
 
-               if (array_contains(&ct_name, p, ct_name_cnt))
+               if (array_contains(&ct_name, p, ct_name_cnt)) {
+                       if (is_hashed)
+                               free(p);
                        continue;
+               }
 
-               if (!add_to_array(&ct_name, p, ct_name_cnt))
+               if (!add_to_array(&ct_name, p, ct_name_cnt)) {
+                       if (is_hashed)
+                               free(p);
                        goto free_cret_list;
+               }
 
                ct_name_cnt++;
 
-               if (!cret)
+               if (!cret) {
+                       if (is_hashed)
+                               free(p);
                        continue;
+               }
 
                c = lxc_container_new(p, lxcpath);
                if (!c) {
                        INFO("Container %s:%s is running but could not be loaded",
                                lxcpath, p);
                        remove_from_array(&ct_name, p, ct_name_cnt--);
+                       if (is_hashed)
+                               free(p);
                        continue;
                }
 
+               if (is_hashed)
+                       free(p);
+
                /*
                 * If this is an anonymous container, then is_defined *can*
                 * return false.  So we don't do that check.  Count on the