提交 550c7767 编写于 作者: L LiFeng

iSulad: fix wrong use of util_free_arry

Signed-off-by: NLiFeng <lifeng68@huawei.com>
上级 65ddd0fd
......@@ -180,7 +180,7 @@ void service_arguments_free(struct service_arguments *args)
free(args->logpath);
args->logpath = NULL;
util_free_array(args->hosts);
util_free_array_by_len(args->hosts, args->hosts_len);
args->hosts = NULL;
args->hosts_len = 0;
......
......@@ -97,7 +97,7 @@ void free_isula_prepare_request(struct isula_prepare_request *req)
req->name = NULL;
free(req->image);
req->image = NULL;
util_free_array(req->storage_opts);
util_free_array_by_len(req->storage_opts, req->storage_opts_len);
req->storage_opts = NULL;
req->storage_opts_len = 0;
free(req);
......@@ -210,10 +210,10 @@ void free_image_metadata(struct image_metadata *data)
}
free(data->id);
data->id = NULL;
util_free_array(data->repo_tags);
util_free_array_by_len(data->repo_tags, data->repo_tags_len);
data->repo_tags = NULL;
data->repo_tags_len = 0;
util_free_array(data->repo_digests);
util_free_array_by_len(data->repo_digests, data->repo_digests_len);
data->repo_digests = NULL;
data->repo_digests_len = 0;
free(data->username);
......
......@@ -220,7 +220,7 @@ void isula_ns_change_files_free(isula_host_config_t *hostconfig)
return;
}
util_free_array(hostconfig->ns_change_files);
util_free_array_by_len(hostconfig->ns_change_files, hostconfig->ns_change_files_len);
hostconfig->ns_change_files = NULL;
hostconfig->ns_change_files_len = 0;
}
......@@ -252,11 +252,11 @@ void isula_host_config_free(isula_host_config_t *hostconfig)
return;
}
util_free_array(hostconfig->cap_add);
util_free_array_by_len(hostconfig->cap_add, hostconfig->cap_add_len);
hostconfig->cap_add = NULL;
hostconfig->cap_add_len = 0;
util_free_array(hostconfig->cap_drop);
util_free_array_by_len(hostconfig->cap_drop, hostconfig->cap_drop_len);
hostconfig->cap_drop = NULL;
hostconfig->cap_drop_len = 0;
......@@ -266,11 +266,11 @@ void isula_host_config_free(isula_host_config_t *hostconfig)
free_json_map_string_string(hostconfig->sysctls);
hostconfig->sysctls = NULL;
util_free_array(hostconfig->devices);
util_free_array_by_len(hostconfig->devices, hostconfig->devices_len);
hostconfig->devices = NULL;
hostconfig->devices_len = 0;
util_free_array(hostconfig->hugetlbs);
util_free_array_by_len(hostconfig->hugetlbs, hostconfig->hugetlbs_len);
hostconfig->hugetlbs = NULL;
hostconfig->hugetlbs_len = 0;
......@@ -292,7 +292,7 @@ void isula_host_config_free(isula_host_config_t *hostconfig)
free(hostconfig->user_remap);
hostconfig->user_remap = NULL;
util_free_array(hostconfig->ulimits);
util_free_array_by_len(hostconfig->ulimits, hostconfig->ulimits_len);
hostconfig->ulimits = NULL;
hostconfig->ulimits_len = 0;
......@@ -311,11 +311,11 @@ void isula_host_config_free(isula_host_config_t *hostconfig)
free(hostconfig->cgroup_parent);
hostconfig->cgroup_parent = NULL;
util_free_array(hostconfig->binds);
util_free_array_by_len(hostconfig->binds, hostconfig->binds_len);
hostconfig->binds = NULL;
hostconfig->binds_len = 0;
util_free_array(hostconfig->blkio_weight_device);
util_free_array_by_len(hostconfig->blkio_weight_device, hostconfig->blkio_weight_device_len);
hostconfig->blkio_weight_device = NULL;
hostconfig->blkio_weight_device_len = 0;
......@@ -332,7 +332,7 @@ void isula_container_config_free(isula_container_config_t *config)
return;
}
util_free_array(config->env);
util_free_array_by_len(config->env, config->env_len);
config->env = NULL;
config->env_len = 0;
......@@ -342,11 +342,11 @@ void isula_container_config_free(isula_container_config_t *config)
free(config->user);
config->user = NULL;
util_free_array(config->mounts);
util_free_array_by_len(config->mounts, config->mounts_len);
config->mounts = NULL;
config->mounts_len = 0;
util_free_array(config->cmd);
util_free_array_by_len(config->cmd, config->cmd_len);
config->cmd = NULL;
config->cmd_len = 0;
......
......@@ -450,7 +450,8 @@ out:
return ret;
}
int parse_output(char **title, char ***process, const char *output, const pid_t *pids, size_t pids_len)
int parse_output(char **title, char ***process, size_t *process_len, const char *output, const pid_t *pids,
size_t pids_len)
{
int ret = 0;
int pid_num = 0;
......@@ -479,6 +480,7 @@ int parse_output(char **title, char ***process, const char *output, const pid_t
}
ret = parse_output_by_lines(*process, tmp, pid_num, stime, pids, pids_len);
*process_len = util_array_len((const char **)(*process));
out:
util_free_array(tmp);
......@@ -755,6 +757,7 @@ static int container_top_cb(container_top_request *request, container_top_respon
char *stderr_buffer = NULL;
char *titles = NULL;
char **processes = NULL;
size_t process_len = 0;
pid_t *pids = NULL;
size_t pids_len = 0;
container_t *cont = NULL;
......@@ -792,17 +795,17 @@ static int container_top_cb(container_top_request *request, container_top_respon
goto pack_response;
}
if (parse_output(&titles, &processes, stdout_buffer, pids, pids_len)) {
if (parse_output(&titles, &processes, &process_len, stdout_buffer, pids, pids_len)) {
ERROR("Failed to parse output!");
cc = ISULAD_ERR_EXEC;
goto pack_response;
}
if (util_array_len((const char **)processes) > SIZE_MAX / sizeof(char *)) {
if (process_len > SIZE_MAX / sizeof(char *)) {
ERROR("invalid processe size");
cc = ISULAD_ERR_EXEC;
goto pack_response;
}
(*response)->processes = util_common_calloc_s(util_array_len((const char **)processes) * sizeof(char *));
(*response)->processes = util_common_calloc_s(process_len * sizeof(char *));
if ((*response)->processes == NULL) {
ERROR("Out of memory");
cc = ISULAD_ERR_EXEC;
......@@ -811,10 +814,10 @@ static int container_top_cb(container_top_request *request, container_top_respon
(*response)->titles = titles;
titles = NULL;
for (i = 0; i < util_array_len((const char **)processes); i++) {
for (i = 0; i < process_len; i++) {
(*response)->processes[i] = util_strdup_s(processes[i]);
}
(*response)->processes_len = util_array_len((const char **)processes);
(*response)->processes_len = process_len;
(void)isulad_monitor_send_container_event(id, TOP, -1, 0, NULL, NULL);
pack_response:
......@@ -830,7 +833,7 @@ pack_response:
stderr_buffer = NULL;
free(pid_args);
free(titles);
util_free_array(processes);
util_free_array_by_len(processes, process_len);
free_log_prefix();
DAEMON_CLEAR_ERRMSG();
return (cc == ISULAD_SUCCESS) ? 0 : -1;
......
......@@ -1874,7 +1874,7 @@ static bool mount_file(oci_runtime_spec *container, const char *src_path, const
out_free:
if (!ret) {
util_free_array(options);
util_free_array_by_len(options, options_len);
free_defs_mount(tmp_mounts);
}
return ret;
......@@ -1924,7 +1924,7 @@ static bool add_host_channel_mount(oci_runtime_spec *container, const host_confi
out_free:
if (!ret) {
util_free_array(options);
util_free_array_by_len(options, options_len);
free_defs_mount(tmp_mounts);
}
return ret;
......@@ -2261,7 +2261,7 @@ static bool add_shm_mount(oci_runtime_spec *container, const char *shm_path)
out_free:
if (!ret) {
util_free_array(options);
util_free_array_by_len(options, options_len);
free_defs_mount(tmp_mounts);
}
return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册