From 57ed3f3f177f0ffad972edda4cfec049f87fb153 Mon Sep 17 00:00:00 2001
From: xuxuepeng <xuxuepeng1@huawei.com>
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 <xuxuepeng1@huawei.com>
---
 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

