[lxc-devel] [lxc/master] cgfsng: fix memory leak in lxc_cpumask_to_cpulist

lifeng68 on Github lxc-bot at linuxcontainers.org
Thu Jun 27 02:34:18 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 344 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190626/48975063/attachment.bin>
-------------- next part --------------
From 46937127fd2ed3a9238040d5fff0f082c5457861 Mon Sep 17 00:00:00 2001
From: LiFeng <lifeng68 at huawei.com>
Date: Wed, 26 Jun 2019 23:54:27 -0400
Subject: [PATCH] cgfsng: fix memory leak in lxc_cpumask_to_cpulist

Signed-off-by: LiFeng <lifeng68 at huawei.com>
---
 src/lxc/cgroups/cgfsng.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 62b7a87b03..b11e8e3362 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -320,6 +320,7 @@ static char *lxc_cpumask_to_cpulist(uint32_t *bitarr, size_t nbits)
 {
 	int ret;
 	size_t i;
+    char *tmp = NULL;
 	char **cpulist = NULL;
 	char numstr[INTTYPE_TO_STRLEN(size_t)] = {0};
 
@@ -343,7 +344,10 @@ static char *lxc_cpumask_to_cpulist(uint32_t *bitarr, size_t nbits)
 	if (!cpulist)
 		return NULL;
 
-	return lxc_string_join(",", (const char **)cpulist, false);
+    tmp = lxc_string_join(",", (const char **)cpulist, false);
+	lxc_free_array((void **)cpulist, free);
+
+	return tmp;
 }
 
 static ssize_t get_max_cpus(char *cpulist)


More information about the lxc-devel mailing list