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