From 5ce82824916d910ba2fc666d2b1d2f15537c5d0c Mon Sep 17 00:00:00 2001
From: zhongtao <zhongtao17@huawei.com>
Date: Mon, 18 Dec 2023 16:07:57 +0800
Subject: [PATCH 179/181] code improve for oci_rmi

Signed-off-by: zhongtao <zhongtao17@huawei.com>
---
 src/daemon/modules/image/oci/oci_image.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/daemon/modules/image/oci/oci_image.c b/src/daemon/modules/image/oci/oci_image.c
index abca4ed7..f525f621 100644
--- a/src/daemon/modules/image/oci/oci_image.c
+++ b/src/daemon/modules/image/oci/oci_image.c
@@ -538,6 +538,17 @@ int oci_rmi(const im_rmi_request *request)
         goto out;
     }
 
+    for (i = 0; i < image_names_len; i++) {
+        if (strcmp(real_image_name, image_names[i]) == 0) {
+            break;
+        }
+    }
+    if (i == image_names_len) {
+        ERROR("Invalid real_image_name");
+        ret = -1;
+        goto out;
+    }
+
     reduced_image_names = (char **)util_smart_calloc_s(sizeof(char *), image_names_len - 1);
     if (reduced_image_names == NULL) {
         ERROR("Out of memory");
@@ -548,11 +559,6 @@ int oci_rmi(const im_rmi_request *request)
     for (i = 0; i < image_names_len; i++) {
         if (strcmp(image_names[i], real_image_name) != 0) {
             reduced_image_names[reduced_image_names_len] = util_strdup_s(image_names[i]);
-            if (reduced_image_names[reduced_image_names_len] == NULL) {
-                ERROR("Out of memory");
-                ret = -1;
-                goto out;
-            }
             reduced_image_names_len++;
         }
     }
-- 
2.42.0

