iSulad/0012-fix-hugetlbs-malloc-length.patch

61 lines
2.4 KiB
Diff
Raw Normal View History

From 069a36a0fbd5202ca6cf0d34550381b3bf1e3eb2 Mon Sep 17 00:00:00 2001
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
Date: Sat, 27 May 2023 17:10:55 +0800
Subject: [PATCH 12/15] fix hugetlbs malloc length
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
---
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