summaryrefslogtreecommitdiff
path: root/0173-bugfix-mem-leak.patch
blob: a477201c5c8860d377f3adc42ac84ce24b1b997b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
From 3144357f7c735e24af180b9352378618ce8b2368 Mon Sep 17 00:00:00 2001
From: liuxu <liuxu156@huawei.com>
Date: Wed, 11 Dec 2024 11:32:06 +0800
Subject: [PATCH 07/11] bugfix: mem leak

Signed-off-by: liuxu <liuxu156@huawei.com>
---
 src/daemon/executor/container_cb/execution_network.c | 2 ++
 src/daemon/modules/service/inspect_container.c       | 2 ++
 src/utils/cutils/utils.c                             | 9 ++++++++-
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/daemon/executor/container_cb/execution_network.c b/src/daemon/executor/container_cb/execution_network.c
index a145e33a..8e34998c 100644
--- a/src/daemon/executor/container_cb/execution_network.c
+++ b/src/daemon/executor/container_cb/execution_network.c
@@ -1213,6 +1213,8 @@ static int generate_network_element(const char **bridges, const size_t len, defs
                                                                                            defs_map_string_object_networks_element *), len);
     if (networks->values == NULL) {
         ERROR("Out of memory ");
+        free(networks->keys);
+        networks->keys = NULL;
         return -1;
     }
 
diff --git a/src/daemon/modules/service/inspect_container.c b/src/daemon/modules/service/inspect_container.c
index 40cf7aa1..ca3955c6 100644
--- a/src/daemon/modules/service/inspect_container.c
+++ b/src/daemon/modules/service/inspect_container.c
@@ -629,6 +629,8 @@ static int do_transform_cni_to_map(container_network_settings *settings)
         util_smart_calloc_s(sizeof(defs_map_string_object_port_bindings_element *), settings->cni_ports_len);
     if (result->values == NULL) {
         ERROR("Out of memory");
+        free(result->keys);
+        result->keys = NULL;
         ret = -1;
         goto out;
     }
diff --git a/src/utils/cutils/utils.c b/src/utils/cutils/utils.c
index 69f6dbf0..cf207acc 100644
--- a/src/utils/cutils/utils.c
+++ b/src/utils/cutils/utils.c
@@ -1609,10 +1609,17 @@ defs_map_string_object *dup_map_string_empty_object(defs_map_string_object *src)
     }
 
     dst->keys = util_smart_calloc_s(sizeof(char *), src->len);
+    if (dst->keys == NULL) {
+        ERROR("Out of memory");
+        ret = -1;
+        goto out;
+    }
     dst->values = util_smart_calloc_s(sizeof(defs_map_string_object_element *), src->len);
-    if (dst->keys == NULL || dst->values == NULL) {
+    if (dst->values == NULL) {
         ERROR("Out of memory");
         ret = -1;
+        free(dst->keys);
+        dst->keys = NULL;
         goto out;
     }
 
-- 
2.23.0