From 05cb3b55d4b7fcde0e8f5eb7a2fb72983d127c64 Mon Sep 17 00:00:00 2001
From: xuxuepeng <xuxuepeng1@huawei.com>
Date: Tue, 9 Apr 2024 06:35:03 +0800
Subject: [PATCH 206/213] Fix memory leak in set_connected_container_shm_path

Signed-off-by: xuxuepeng <xuxuepeng1@huawei.com>
---
 src/daemon/modules/spec/specs_mount.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/daemon/modules/spec/specs_mount.c b/src/daemon/modules/spec/specs_mount.c
index 4b56200e..6adb6a5b 100644
--- a/src/daemon/modules/spec/specs_mount.c
+++ b/src/daemon/modules/spec/specs_mount.c
@@ -2854,23 +2854,25 @@ static inline int set_sharable_ipc_mode(host_config *host_spec, container_config
 
 static inline int set_connected_container_shm_path(host_config *host_spec, container_config_v2_common_config *v2_spec)
 {
+    int ret = 0;
     container_t *cont = NULL;
     char *tmp_cid = NULL;
-    char *right_path = NULL;
 
     tmp_cid = namespace_get_connected_container(host_spec->ipc_mode);
     cont = containers_store_get(tmp_cid);
     if (cont == NULL) {
         ERROR("Invalid share path: %s", host_spec->ipc_mode);
-        return -1;
-    }
-    right_path = util_strdup_s(cont->common_config->shm_path);
-    container_unref(cont);
+        ret = -1;
+    } else {
+        char *right_path = util_strdup_s(cont->common_config->shm_path);
+        container_unref(cont);
 
-    free(v2_spec->shm_path);
-    v2_spec->shm_path = right_path;
+        free(v2_spec->shm_path);
+        v2_spec->shm_path = right_path;
+    }
 
-    return 0;
+    free(tmp_cid);
+    return ret;
 }
 
 #define SHM_MOUNT_POINT "/dev/shm"
-- 
2.25.1

