From d4f524ef82ffdf2aed4847fa25795894a7bb7eda Mon Sep 17 00:00:00 2001
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
Date: Tue, 28 Mar 2023 10:14:22 +0800
Subject: [PATCH 35/46] fix inspect data memleak

Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
---
 src/daemon/entry/cri/cni_network_plugin.cc                 | 2 +-
 src/daemon/entry/cri/cri_container_manager_service_impl.cc | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/daemon/entry/cri/cni_network_plugin.cc b/src/daemon/entry/cri/cni_network_plugin.cc
index 02e75ffe..8cad0126 100644
--- a/src/daemon/entry/cri/cni_network_plugin.cc
+++ b/src/daemon/entry/cri/cni_network_plugin.cc
@@ -478,7 +478,7 @@ auto CniNetworkPlugin::GetNetNS(const std::string &podSandboxID, Errors &err) ->
 
     container_inspect *inspect_data = CRIHelpers::InspectContainer(podSandboxID, err, false);
     if (inspect_data == nullptr) {
-        goto cleanup;
+        return result;
     }
     if (inspect_data->state->pid == 0) {
         err.Errorf("cannot find network namespace for the terminated container %s", podSandboxID.c_str());
diff --git a/src/daemon/entry/cri/cri_container_manager_service_impl.cc b/src/daemon/entry/cri/cri_container_manager_service_impl.cc
index 0fc1884f..d406496e 100644
--- a/src/daemon/entry/cri/cri_container_manager_service_impl.cc
+++ b/src/daemon/entry/cri/cri_container_manager_service_impl.cc
@@ -1100,6 +1100,7 @@ ContainerManagerServiceImpl::ContainerStatus(const std::string &containerID, Err
     ContainerStatusPtr contStatus(new (std::nothrow) runtime::v1alpha2::ContainerStatus);
     if (contStatus == nullptr) {
         error.SetError("Out of memory");
+        free_container_inspect(inspect);
         return nullptr;
     }
 
-- 
2.25.1

