79 lines
2.2 KiB
Diff
79 lines
2.2 KiB
Diff
From e430c3656032d2f112b7ec7eb99e07f05c300e8b Mon Sep 17 00:00:00 2001
|
|
From: tanyifeng <tanyifeng1@huawei.com>
|
|
Date: Mon, 14 Jan 2019 21:24:25 +0800
|
|
Subject: [PATCH 027/139] fix bug of memory leak
|
|
|
|
Signed-off-by: LiFeng <lifeng68@huawei.com>
|
|
---
|
|
src/lxc/conf.c | 11 +++++++++++
|
|
src/lxc/conf.h | 1 +
|
|
src/lxc/lxccontainer.c | 11 +++++++----
|
|
3 files changed, 19 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
|
|
index 6a14de1..e076bf2 100644
|
|
--- a/src/lxc/conf.c
|
|
+++ b/src/lxc/conf.c
|
|
@@ -4822,6 +4822,16 @@ int lxc_clear_procs(struct lxc_conf *c, const char *key)
|
|
return 0;
|
|
}
|
|
|
|
+int lxc_clear_namespace(struct lxc_conf *c)
|
|
+{
|
|
+ int i;
|
|
+ for (i = 0; i < LXC_NS_MAX; i++) {
|
|
+ free(c->ns_share[i]);
|
|
+ c->ns_share[i] = NULL;
|
|
+ }
|
|
+ return 0;
|
|
+}
|
|
+
|
|
int lxc_clear_groups(struct lxc_conf *c)
|
|
{
|
|
struct lxc_list *it, *next;
|
|
@@ -5036,6 +5046,7 @@ void lxc_conf_free(struct lxc_conf *conf)
|
|
lxc_clear_limits(conf, "lxc.prlimit");
|
|
lxc_clear_sysctls(conf, "lxc.sysctl");
|
|
lxc_clear_procs(conf, "lxc.proc");
|
|
+ lxc_clear_namespace(conf);
|
|
free(conf->cgroup_meta.dir);
|
|
free(conf->cgroup_meta.controllers);
|
|
/* isulad add begin */
|
|
diff --git a/src/lxc/conf.h b/src/lxc/conf.h
|
|
index 2263e47..44feb98 100644
|
|
--- a/src/lxc/conf.h
|
|
+++ b/src/lxc/conf.h
|
|
@@ -491,6 +491,7 @@ extern int setup_sysctl_parameters(struct lxc_list *sysctls);
|
|
extern int lxc_clear_sysctls(struct lxc_conf *c, const char *key);
|
|
extern int setup_proc_filesystem(struct lxc_list *procs, pid_t pid);
|
|
extern int lxc_clear_procs(struct lxc_conf *c, const char *key);
|
|
+extern int lxc_clear_namespace(struct lxc_conf *c);
|
|
|
|
/* isulad add begin */
|
|
int lxc_clear_init_args(struct lxc_conf *lxc_conf);
|
|
diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
|
|
index 81c0ec3..e6272fc 100644
|
|
--- a/src/lxc/lxccontainer.c
|
|
+++ b/src/lxc/lxccontainer.c
|
|
@@ -5418,10 +5418,13 @@ int list_active_containers(const char *lxcpath, char ***nret,
|
|
continue;
|
|
}
|
|
|
|
- if (array_contains(&ct_name, p, ct_name_cnt)) {
|
|
- if (is_hashed)
|
|
- free(p);
|
|
- continue;
|
|
+
|
|
+ if (ct_name && ct_name_cnt) {
|
|
+ if (array_contains(&ct_name, p, ct_name_cnt)) {
|
|
+ if (is_hashed)
|
|
+ free(p);
|
|
+ continue;
|
|
+ }
|
|
}
|
|
|
|
if (!add_to_array(&ct_name, p, ct_name_cnt)) {
|
|
--
|
|
1.8.3.1
|
|
|