From a9055584290760b47ae091c0c42b35ba815cf6f6 Mon Sep 17 00:00:00 2001 From: zhangxiaoyu Date: Mon, 29 May 2023 17:16:10 +0800 Subject: [PATCH] bugfix for memleak and malloc Signed-off-by: zhangxiaoyu --- 0010-fix-memory-leak-of-top_layer.patch | 130 ++++++++++ ...xit-codes-between-shim-and-container.patch | 223 ++++++++++++++++++ 0012-fix-hugetlbs-malloc-length.patch | 60 +++++ 0013-fix-forget-to-set-return-value.patch | 25 ++ ...fine-in-local-and-use-correctly-type.patch | 33 +++ ...t-the-changes-in-util_smart_calloc_s.patch | 72 ++++++ iSulad.spec | 14 +- 7 files changed, 556 insertions(+), 1 deletion(-) create mode 100644 0010-fix-memory-leak-of-top_layer.patch create mode 100644 0011-distinguishing-exit-codes-between-shim-and-container.patch create mode 100644 0012-fix-hugetlbs-malloc-length.patch create mode 100644 0013-fix-forget-to-set-return-value.patch create mode 100644 0014-ensure-define-in-local-and-use-correctly-type.patch create mode 100644 0015-Revert-the-changes-in-util_smart_calloc_s.patch diff --git a/0010-fix-memory-leak-of-top_layer.patch b/0010-fix-memory-leak-of-top_layer.patch new file mode 100644 index 0000000..d840c5c --- /dev/null +++ b/0010-fix-memory-leak-of-top_layer.patch @@ -0,0 +1,130 @@ +From 10d3f420735925bcc747384198fdc07bb8faf0c2 Mon Sep 17 00:00:00 2001 +From: "Neil.wrz" +Date: Wed, 24 May 2023 18:35:33 -0700 +Subject: [PATCH 10/15] fix memory leak of top_layer + +Signed-off-by: Neil.wrz +--- + .../oci/storage/image_store/image_store.c | 3 +- + .../remote_layer_support/image_remote_impl.c | 50 +++++++++++++------ + .../overlay_remote_impl.c | 4 +- + 3 files changed, 38 insertions(+), 19 deletions(-) + +diff --git a/src/daemon/modules/image/oci/storage/image_store/image_store.c b/src/daemon/modules/image/oci/storage/image_store/image_store.c +index 473ba3c8..65b90832 100644 +--- a/src/daemon/modules/image/oci/storage/image_store/image_store.c ++++ b/src/daemon/modules/image/oci/storage/image_store/image_store.c +@@ -3681,7 +3681,8 @@ int remote_append_image_by_directory_with_lock(const char *id) + nret = snprintf(image_path, sizeof(image_path), "%s/%s", g_image_store->dir, id); + if (nret < 0 || (size_t)nret >= sizeof(image_path)) { + ERROR("Failed to get image path"); +- return -1; ++ ret = -1; ++ goto out; + } + + ret = append_image_by_directory(image_path); +diff --git a/src/daemon/modules/image/oci/storage/remote_layer_support/image_remote_impl.c b/src/daemon/modules/image/oci/storage/remote_layer_support/image_remote_impl.c +index 92bf901d..b4a53ec1 100644 +--- a/src/daemon/modules/image/oci/storage/remote_layer_support/image_remote_impl.c ++++ b/src/daemon/modules/image/oci/storage/remote_layer_support/image_remote_impl.c +@@ -126,11 +126,43 @@ out: + return ret; + } + ++static int check_top_layer_and_add_image(const char *id) ++{ ++ char *top_layer = NULL; ++ int ret = 0; ++ ++ top_layer = remote_image_get_top_layer_from_json(id); ++ if (top_layer == NULL) { ++ WARN("Can't get top layer id for image: %s, image not add", id); ++ return 0; ++ } ++ ++ if (!remote_layer_layer_valid(top_layer)) { ++ WARN("Current not find valid under layer, remote image:%s not add", id); ++ if (!map_remove(image_byid_new, (void *)id)) { ++ WARN("image %s will not be loaded from remote.", id); ++ } ++ goto out; ++ } ++ ++ if (remote_append_image_by_directory_with_lock(id) != 0) { ++ ERROR("Failed to load image into memrory: %s", id); ++ if (!map_remove(image_byid_new, (void *)id)) { ++ WARN("image %s will not be loaded from remote", id); ++ } ++ ret = -1; ++ } ++ ++out: ++ free(top_layer); ++ ++ return ret; ++} ++ + static int remote_image_add(void *data) + { + char **array_added = NULL; + char **array_deleted = NULL; +- char *top_layer = NULL; + map_t *tmp_map = NULL; + bool exist = true; + size_t i = 0; +@@ -144,20 +176,7 @@ static int remote_image_add(void *data) + array_deleted = remote_deleted_layers(image_byid_old, image_byid_new); + + for (i = 0; i < util_array_len((const char **)array_added); i++) { +- top_layer = remote_image_get_top_layer_from_json(array_added[i]); +- if (top_layer != NULL && !remote_layer_layer_valid(top_layer)) { +- WARN("Current not find valid under layer, remoet image:%s not added", array_added[i]); +- if (!map_remove(image_byid_new, (void *)array_added[i])) { +- WARN("image %s will not be loaded from remote.", array_added[i]); +- } +- continue; +- } +- +- if (remote_append_image_by_directory_with_lock(array_added[i]) != 0) { +- ERROR("Failed to load image into memrory: %s", array_added[i]); +- if (!map_remove(image_byid_new, (void *)array_added[i])) { +- WARN("image %s will not be loaded from remote", array_added[i]); +- } ++ if (check_top_layer_and_add_image(array_added[i]) != 0) { + ret = -1; + } + } +@@ -179,7 +198,6 @@ static int remote_image_add(void *data) + + util_free_array(array_added); + util_free_array(array_deleted); +- free(top_layer); + + return ret; + } +diff --git a/src/daemon/modules/image/oci/storage/remote_layer_support/overlay_remote_impl.c b/src/daemon/modules/image/oci/storage/remote_layer_support/overlay_remote_impl.c +index 30caf175..238506c2 100644 +--- a/src/daemon/modules/image/oci/storage/remote_layer_support/overlay_remote_impl.c ++++ b/src/daemon/modules/image/oci/storage/remote_layer_support/overlay_remote_impl.c +@@ -292,7 +292,7 @@ free_out: + return ret; + } + +-static int remote_image_add(struct remote_overlay_data *data) ++static int remote_overlay_add(struct remote_overlay_data *data) + { + int ret = 0; + char **array_added = NULL; +@@ -346,7 +346,7 @@ void remote_overlay_refresh(struct remote_overlay_data *data) + return; + } + +- if (remote_image_add(data) != 0) { ++ if (remote_overlay_add(data) != 0) { + ERROR("refresh overlay failed"); + } + } +-- +2.25.1 + diff --git a/0011-distinguishing-exit-codes-between-shim-and-container.patch b/0011-distinguishing-exit-codes-between-shim-and-container.patch new file mode 100644 index 0000000..1cbc3b5 --- /dev/null +++ b/0011-distinguishing-exit-codes-between-shim-and-container.patch @@ -0,0 +1,223 @@ +From b878dde993c8da90788fae5c2a463812001bff30 Mon Sep 17 00:00:00 2001 +From: zhongtao +Date: Wed, 24 May 2023 09:35:35 +0800 +Subject: [PATCH 11/15] distinguishing exit codes between shim and container + processes + +Signed-off-by: zhongtao +--- + src/cmd/isulad-shim/main.c | 10 ++- + src/cmd/isulad-shim/process.c | 8 ++- + .../modules/runtime/isula/isula_rt_ops.c | 63 +++++++++++++++---- + 3 files changed, 64 insertions(+), 17 deletions(-) + +diff --git a/src/cmd/isulad-shim/main.c b/src/cmd/isulad-shim/main.c +index ed55805c..e2625aac 100644 +--- a/src/cmd/isulad-shim/main.c ++++ b/src/cmd/isulad-shim/main.c +@@ -160,5 +160,13 @@ int main(int argc, char **argv) + + released_timeout_exit(); + +- return process_signal_handle_routine(p, tid_epoll, timeout); ++ ret = process_signal_handle_routine(p, tid_epoll, timeout); ++ if (ret == SHIM_ERR) { ++ exit(EXIT_FAILURE); ++ } ++ if (ret == SHIM_ERR_TIMEOUT) { ++ exit(SHIM_EXIT_TIMEOUT); ++ } ++ ++ exit(EXIT_SUCCESS); + } +diff --git a/src/cmd/isulad-shim/process.c b/src/cmd/isulad-shim/process.c +index 6ad50c53..1d070f83 100644 +--- a/src/cmd/isulad-shim/process.c ++++ b/src/cmd/isulad-shim/process.c +@@ -1269,7 +1269,7 @@ int process_signal_handle_routine(process_t *p, const pthread_t tid_epoll, const + nret = kill(p->ctr_pid, SIGKILL); + if (nret < 0 && errno != ESRCH) { + write_message(g_log_fd, ERR_MSG, "Can not kill process (pid=%d) with SIGKILL", p->ctr_pid); +- exit(EXIT_FAILURE); ++ return SHIM_ERR; + } + } + +@@ -1307,8 +1307,10 @@ int process_signal_handle_routine(process_t *p, const pthread_t tid_epoll, const + + if (ret == SHIM_ERR_TIMEOUT) { + write_message(g_log_fd, INFO_MSG, "Wait %d timeout", p->ctr_pid); +- exit(SHIM_EXIT_TIMEOUT); ++ return SHIM_ERR_TIMEOUT; + } +- return status; + ++ // write container process exit_code in stdout ++ (void)write_nointr(STDOUT_FILENO, &status, sizeof(int)); ++ return SHIM_OK; + } +diff --git a/src/daemon/modules/runtime/isula/isula_rt_ops.c b/src/daemon/modules/runtime/isula/isula_rt_ops.c +index 07f714f0..84a081c1 100644 +--- a/src/daemon/modules/runtime/isula/isula_rt_ops.c ++++ b/src/daemon/modules/runtime/isula/isula_rt_ops.c +@@ -677,9 +677,9 @@ static int runtime_call_kill_and_check(const char *workdir, const char *runtime, + static int runtime_call_delete_force(const char *workdir, const char *runtime, const char *id) + { + const char *opts[1] = { "--force" }; +- // delete succeed, return 0; +- // When the runc version is less than or equal to v1.0.0-rc3, +- // if the container does not exist when force deleting it, ++ // delete succeed, return 0; ++ // When the runc version is less than or equal to v1.0.0-rc3, ++ // if the container does not exist when force deleting it, + // runc will report an error and isulad does not need to retry the deletion again. + // related PR ID:d1a743674a98e23d348b29f52c43436356f56b79 + // non_existent_output_check succeed, return 0; +@@ -704,11 +704,16 @@ static int status_to_exit_code(int status) + return exit_code; + } + ++/* ++ exit_code records the exit code of the container, obtained by reading the stdout of isulad-shim; ++ shim_exit_code records the exit code of isulad-shim, obtained through waitpid; ++*/ + static int shim_create(bool fg, const char *id, const char *workdir, const char *bundle, const char *runtime_cmd, +- int *exit_code, const char* timeout) ++ int *exit_code, const char* timeout, int* shim_exit_code) + { + pid_t pid = 0; + int exec_fd[2] = { -1, -1 }; ++ int shim_stdout_pipe[2] = { -1, -1 }; + int num = 0; + int ret = 0; + char exec_buff[BUFSIZ + 1] = { 0 }; +@@ -738,11 +743,18 @@ static int shim_create(bool fg, const char *id, const char *workdir, const char + return -1; + } + ++ if (pipe2(shim_stdout_pipe, O_CLOEXEC) != 0) { ++ ERROR("Failed to create pipe for shim exit code"); ++ return -1; ++ } ++ + pid = fork(); + if (pid < 0) { + ERROR("Failed fork for shim parent %s", strerror(errno)); + close(exec_fd[0]); + close(exec_fd[1]); ++ close(shim_stdout_pipe[0]); ++ close(shim_stdout_pipe[1]); + return -1; + } + +@@ -777,12 +789,21 @@ static int shim_create(bool fg, const char *id, const char *workdir, const char + realexec: + /* real shim process. */ + close(exec_fd[0]); ++ close(shim_stdout_pipe[0]); ++ // child process, dup2 shim_stdout_pipe[1] to STDOUT ++ if (dup2(shim_stdout_pipe[1], STDOUT_FILENO) < 0) { ++ (void)dprintf(exec_fd[1], "Dup fd error: %s", strerror(errno)); ++ exit(EXIT_FAILURE); ++ } ++ + if (setsid() < 0) { + (void)dprintf(exec_fd[1], "%s: failed setsid for process %d", id, getpid()); + exit(EXIT_FAILURE); + } +- +- if (util_check_inherited(true, exec_fd[1]) != 0) { ++ int ignore_fd[2] = {-1, -1}; ++ ignore_fd[0] = exec_fd[1]; ++ ignore_fd[1] = shim_stdout_pipe[1]; ++ if (util_check_inherited_exclude_fds(true, ignore_fd, 2) != 0) { + (void)dprintf(exec_fd[1], "close inherited fds failed"); + } + +@@ -791,24 +812,38 @@ realexec: + } + + close(exec_fd[1]); ++ close(shim_stdout_pipe[1]); + num = util_read_nointr(exec_fd[0], exec_buff, sizeof(exec_buff) - 1); + close(exec_fd[0]); + if (num > 0) { +- ERROR("exec failed: %s", exec_buff); ++ ERROR("Exec failed: %s", exec_buff); + ret = -1; + goto out; + } + + status = util_wait_for_pid_status(pid); + if (status < 0) { +- ERROR("failed wait shim-parent %d exit %s", pid, strerror(errno)); ++ ERROR("Failed wait shim-parent %d exit %s", pid, strerror(errno)); + ret = -1; + goto out; + } + +- if (exit_code != NULL) { +- *exit_code = status_to_exit_code(status); ++ *shim_exit_code = status_to_exit_code(status); ++ if (*shim_exit_code != 0) { ++ ERROR("Isulad-shim exit error"); ++ ret = -1; ++ goto out; ++ } ++ ++ if (exit_code == NULL) { ++ goto out; ++ } ++ ret = util_read_nointr(shim_stdout_pipe[0], exit_code, sizeof(int)); ++ close(shim_stdout_pipe[0]); ++ if (ret <= 0) { ++ *exit_code = 137; + } ++ ret = 0; + + out: + if (ret != 0) { +@@ -892,6 +927,7 @@ int rt_isula_create(const char *id, const char *runtime, const rt_create_params_ + int ret = 0; + char workdir[PATH_MAX] = { 0 }; + shim_client_process_state p = { 0 }; ++ int shim_exit_code = 0; + + if (id == NULL || runtime == NULL || params == NULL) { + ERROR("nullptr arguments not allowed"); +@@ -924,7 +960,7 @@ int rt_isula_create(const char *id, const char *runtime, const rt_create_params_ + } + + get_runtime_cmd(runtime, &cmd); +- ret = shim_create(false, id, workdir, params->bundle, cmd, NULL, NULL); ++ ret = shim_create(false, id, workdir, params->bundle, cmd, NULL, NULL, &shim_exit_code); + if (ret != 0) { + runtime_call_delete_force(workdir, runtime, id); + ERROR("%s: failed create shim process", id); +@@ -1125,6 +1161,7 @@ int rt_isula_exec(const char *id, const char *runtime, const rt_exec_params_t *p + int pid = 0; + shim_client_process_state p = { 0 }; + char *timeout = NULL; ++ int shim_exit_code = 0; + + if (id == NULL || runtime == NULL || params == NULL || exit_code == NULL) { + ERROR("nullptr arguments not allowed"); +@@ -1199,13 +1236,13 @@ int rt_isula_exec(const char *id, const char *runtime, const rt_exec_params_t *p + } + } + +- ret = shim_create(fg_exec(params), id, workdir, bundle, cmd, exit_code, timeout); ++ ret = shim_create(fg_exec(params), id, workdir, bundle, cmd, exit_code, timeout, &shim_exit_code); + if (ret != 0) { + ERROR("%s: failed create shim process for exec %s", id, exec_id); + goto errlog_out; + } + +- if (*exit_code == SHIM_EXIT_TIMEOUT) { ++ if (shim_exit_code == SHIM_EXIT_TIMEOUT) { + ret = -1; + isulad_set_error_message("Exec container error;exec timeout"); + ERROR("isulad-shim %d exit for execing timeout", pid); +-- +2.25.1 + diff --git a/0012-fix-hugetlbs-malloc-length.patch b/0012-fix-hugetlbs-malloc-length.patch new file mode 100644 index 0000000..6d8c538 --- /dev/null +++ b/0012-fix-hugetlbs-malloc-length.patch @@ -0,0 +1,60 @@ +From 069a36a0fbd5202ca6cf0d34550381b3bf1e3eb2 Mon Sep 17 00:00:00 2001 +From: zhangxiaoyu +Date: Sat, 27 May 2023 17:10:55 +0800 +Subject: [PATCH 12/15] fix hugetlbs malloc length + +Signed-off-by: zhangxiaoyu +--- + src/cmd/isulad-shim/common.c | 5 ++++- + src/daemon/modules/service/inspect_container.c | 2 +- + src/utils/cutils/utils.c | 5 ++++- + 3 files changed, 9 insertions(+), 3 deletions(-) + +diff --git a/src/cmd/isulad-shim/common.c b/src/cmd/isulad-shim/common.c +index 3787cdfb..7fa3c836 100644 +--- a/src/cmd/isulad-shim/common.c ++++ b/src/cmd/isulad-shim/common.c +@@ -381,7 +381,10 @@ void util_usleep_nointerupt(unsigned long usec) + + void *util_smart_calloc_s(size_t unit_size, size_t count) + { +- if (unit_size == 0) { ++ // If count or size is 0, ++ // then calloc() returns either NULL, ++ // or a unique pointer value that can later be successfully passed to free() ++ if (unit_size == 0 || count == 0) { + return NULL; + } + +diff --git a/src/daemon/modules/service/inspect_container.c b/src/daemon/modules/service/inspect_container.c +index b1050bc7..40cf7aa1 100644 +--- a/src/daemon/modules/service/inspect_container.c ++++ b/src/daemon/modules/service/inspect_container.c +@@ -751,7 +751,7 @@ static int pack_inspect_resources(const container_t *cont, container_inspect *in + resources->memory = cont->hostconfig->memory; + resources->memory_swap = cont->hostconfig->memory_swap; + resources->hugetlbs = util_smart_calloc_s(sizeof(container_inspect_resources_hugetlbs_element *), +- resources->hugetlbs_len); ++ cont->hostconfig->hugetlbs_len); + if (resources->hugetlbs == NULL) { + ERROR("Out of memory"); + ret = -1; +diff --git a/src/utils/cutils/utils.c b/src/utils/cutils/utils.c +index 3500d8f8..103c7c5b 100644 +--- a/src/utils/cutils/utils.c ++++ b/src/utils/cutils/utils.c +@@ -253,7 +253,10 @@ int util_sig_parse(const char *sig_name) + + void *util_smart_calloc_s(size_t unit_size, size_t count) + { +- if (unit_size == 0) { ++ // If count or size is 0, ++ // then calloc() returns either NULL, ++ // or a unique pointer value that can later be successfully passed to free() ++ if (unit_size == 0 || count == 0) { + return NULL; + } + +-- +2.25.1 + diff --git a/0013-fix-forget-to-set-return-value.patch b/0013-fix-forget-to-set-return-value.patch new file mode 100644 index 0000000..5aaeb39 --- /dev/null +++ b/0013-fix-forget-to-set-return-value.patch @@ -0,0 +1,25 @@ +From 165912f5f5a8346613f75ec16c4c5b2aeb7e81e7 Mon Sep 17 00:00:00 2001 +From: "Neil.wrz" +Date: Sat, 27 May 2023 02:44:46 -0700 +Subject: [PATCH 13/15] fix forget to set return value + +Signed-off-by: Neil.wrz +--- + .../image/oci/storage/remote_layer_support/ro_symlink_maintain.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/src/daemon/modules/image/oci/storage/remote_layer_support/ro_symlink_maintain.c b/src/daemon/modules/image/oci/storage/remote_layer_support/ro_symlink_maintain.c +index 2bcc43e6..4d234aab 100644 +--- a/src/daemon/modules/image/oci/storage/remote_layer_support/ro_symlink_maintain.c ++++ b/src/daemon/modules/image/oci/storage/remote_layer_support/ro_symlink_maintain.c +@@ -135,6 +135,7 @@ static int do_build_ro_dir(const char *home, const char *id) + + nret = asprintf(&ro_layer_dir, "%s/%s/%s", home, REMOTE_RO_LAYER_DIR, id); + if (nret < 0 || nret > PATH_MAX) { ++ ret = -1; + SYSERROR("Failed to create ro layer dir path"); + goto out; + } +-- +2.25.1 + diff --git a/0014-ensure-define-in-local-and-use-correctly-type.patch b/0014-ensure-define-in-local-and-use-correctly-type.patch new file mode 100644 index 0000000..8a48d49 --- /dev/null +++ b/0014-ensure-define-in-local-and-use-correctly-type.patch @@ -0,0 +1,33 @@ +From 1f71bbfb6ac54d0e8c4c4a4b9cf669301939dc65 Mon Sep 17 00:00:00 2001 +From: haozi007 +Date: Sat, 27 May 2023 10:18:40 +0800 +Subject: [PATCH 14/15] ensure define in local and use correctly type + +Signed-off-by: haozi007 +--- + src/cmd/isula/volume/prune.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/cmd/isula/volume/prune.c b/src/cmd/isula/volume/prune.c +index 2a3bca3e..c8d632ed 100644 +--- a/src/cmd/isula/volume/prune.c ++++ b/src/cmd/isula/volume/prune.c +@@ -85,7 +85,6 @@ int cmd_volume_prune_main(int argc, const char **argv) + command_t cmd; + char **volumes = NULL; + size_t volumes_len = 0; +- char ch = 'n'; + struct command_option options[] = { LOG_OPTIONS(lconf) COMMON_OPTIONS(g_cmd_volume_prune_args) + PRUNE_OPTIONS(g_cmd_volume_prune_args) + }; +@@ -113,6 +112,7 @@ int cmd_volume_prune_main(int argc, const char **argv) + } + + if (!g_cmd_volume_prune_args.force) { ++ int ch; + printf("WARNING! This will remove all local volumes not used by at least one container.\n"); + printf("Are you sure you want to continue? [y/N]"); + ch = getchar(); +-- +2.25.1 + diff --git a/0015-Revert-the-changes-in-util_smart_calloc_s.patch b/0015-Revert-the-changes-in-util_smart_calloc_s.patch new file mode 100644 index 0000000..7de6c45 --- /dev/null +++ b/0015-Revert-the-changes-in-util_smart_calloc_s.patch @@ -0,0 +1,72 @@ +From 57ed3f3f177f0ffad972edda4cfec049f87fb153 Mon Sep 17 00:00:00 2001 +From: xuxuepeng +Date: Mon, 29 May 2023 16:19:38 +0800 +Subject: [PATCH 15/15] Revert the changes in util_smart_calloc_s + +Signed-off-by: xuxuepeng +--- + src/cmd/isulad-shim/common.c | 11 +++++++---- + src/utils/cutils/utils.c | 11 +++++++---- + 2 files changed, 14 insertions(+), 8 deletions(-) + +diff --git a/src/cmd/isulad-shim/common.c b/src/cmd/isulad-shim/common.c +index 7fa3c836..fc4f6035 100644 +--- a/src/cmd/isulad-shim/common.c ++++ b/src/cmd/isulad-shim/common.c +@@ -381,10 +381,7 @@ void util_usleep_nointerupt(unsigned long usec) + + void *util_smart_calloc_s(size_t unit_size, size_t count) + { +- // If count or size is 0, +- // then calloc() returns either NULL, +- // or a unique pointer value that can later be successfully passed to free() +- if (unit_size == 0 || count == 0) { ++ if (unit_size == 0) { + return NULL; + } + +@@ -392,6 +389,12 @@ void *util_smart_calloc_s(size_t unit_size, size_t count) + return NULL; + } + ++ // If count or size is 0, ++ // then calloc() returns either NULL, ++ // or a unique pointer value that can later be successfully passed to free() ++ // In current linux implementation, if the size for memory allocation is 0, ++ // then a unique pointer value is returned. If the return value is Null pointer, ++ // it means out of memory. + return calloc(count, unit_size); + } + +diff --git a/src/utils/cutils/utils.c b/src/utils/cutils/utils.c +index 103c7c5b..1e17853a 100644 +--- a/src/utils/cutils/utils.c ++++ b/src/utils/cutils/utils.c +@@ -253,10 +253,7 @@ int util_sig_parse(const char *sig_name) + + void *util_smart_calloc_s(size_t unit_size, size_t count) + { +- // If count or size is 0, +- // then calloc() returns either NULL, +- // or a unique pointer value that can later be successfully passed to free() +- if (unit_size == 0 || count == 0) { ++ if (unit_size == 0 ) { + return NULL; + } + +@@ -264,6 +261,12 @@ void *util_smart_calloc_s(size_t unit_size, size_t count) + return NULL; + } + ++ // If count or size is 0, ++ // then calloc() returns either NULL, ++ // or a unique pointer value that can later be successfully passed to free() ++ // In current linux implementation, if the size for memory allocation is 0, ++ // then a unique pointer value is returned. If the return value is Null pointer, ++ // it means out of memory. + return calloc(count, unit_size); + } + +-- +2.25.1 + diff --git a/iSulad.spec b/iSulad.spec index 3868b11..2697cee 100644 --- a/iSulad.spec +++ b/iSulad.spec @@ -1,5 +1,5 @@ %global _version 2.1.2 -%global _release 3 +%global _release 4 %global is_systemd 1 %global enable_shimv2 1 %global is_embedded 1 @@ -22,6 +22,12 @@ Patch0006: 0006-restore-execSync-return-value.patch Patch0007: 0007-reinforce-cri_stream.sh-and-health_check.sh.patch Patch0008: 0008-reinforce-omit-health_check.sh.patch Patch0009: 0009-fix-memory-leak-and-array-access-out-of-range.patch +Patch0010: 0010-fix-memory-leak-of-top_layer.patch +Patch0011: 0011-distinguishing-exit-codes-between-shim-and-container.patch +Patch0012: 0012-fix-hugetlbs-malloc-length.patch +Patch0013: 0013-fix-forget-to-set-return-value.patch +Patch0014: 0014-ensure-define-in-local-and-use-correctly-type.patch +Patch0015: 0015-Revert-the-changes-in-util_smart_calloc_s.patch %ifarch x86_64 aarch64 Provides: libhttpclient.so()(64bit) @@ -264,6 +270,12 @@ fi %endif %changelog +* Mon May 29 2023 zhangxiaoyu - 2.1.2-4 +- Type: bugfix +- ID: NA +- SUG: NA +- DESC: bugfix for memleak and malloc + * Thu May 25 2023 zhongtao - 2.1.2-3 - Type: bugfix - ID: NA