Merge pull request #2289 from lifeng68/Fix_mem_leak_list_active_containers

Fix memory leak in list_active_containers
This commit is contained in:
Christian Brauner 2018-04-24 15:14:25 +02:00 committed by GitHub
commit fca96eb6da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4973,32 +4973,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