From dcc50d14398f1bfcde7c41e7480928e6c98b52d9 Mon Sep 17 00:00:00 2001
From: LiFeng <lifeng68@huawei.com>
Date: Thu, 16 Apr 2020 12:35:45 +0800
Subject: [PATCH 41/49] build: fix some bug in free memory

Signed-off-by: LiFeng <lifeng68@huawei.com>
---
 src/lxc/lxccontainer.c | 10 ++++++++++
 src/lxc/string_utils.c |  1 +
 2 files changed, 11 insertions(+)

diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index ab10ac6..818848a 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -6006,11 +6006,21 @@ int list_active_containers(const char *lxcpath, char ***nret,
 				continue;
 		}
 
+#ifdef HAVE_ISULAD
+		if (ct_name && ct_name_cnt) {
+			if (array_contains(&ct_name, p, ct_name_cnt)) {
+				if (is_hashed)
+					free(p);
+				continue;
+			}
+		}
+#else
 		if (array_contains(&ct_name, p, ct_name_cnt)) {
 			if (is_hashed)
 				free(p);
 			continue;
 		}
+#endif
 
 		if (!add_to_array(&ct_name, p, ct_name_cnt)) {
 			if (is_hashed)
diff --git a/src/lxc/string_utils.c b/src/lxc/string_utils.c
index dcb1160..9118add 100644
--- a/src/lxc/string_utils.c
+++ b/src/lxc/string_utils.c
@@ -501,6 +501,7 @@ int lxc_grow_array(void ***array, size_t *capacity, size_t new_size, size_t capa
 	/* first time around, catch some trivial mistakes of the user
 	 * only initializing one of these */
 	if (!*array || !*capacity) {
+		free(*array);
 		*array = NULL;
 		*capacity = 0;
 	}
-- 
1.8.3.1

