[lxc-devel] [PATCH] coverity: fix resource leak

Dwight Engen dwight.engen at oracle.com
Fri Feb 14 14:49:51 UTC 2014


also fix the check if the string will fit the local buffer

Signed-off-by: Dwight Engen <dwight.engen at oracle.com>
---
 src/lxc/cgmanager.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/lxc/cgmanager.c b/src/lxc/cgmanager.c
index 41ba3d3..e4bd734 100644
--- a/src/lxc/cgmanager.c
+++ b/src/lxc/cgmanager.c
@@ -422,8 +422,10 @@ static inline bool cgm_create(void *hdata)
 	tmp = lxc_string_replace("%n", d->name, d->cgroup_pattern);
 	if (!tmp)
 		return false;
-	if (strlen(tmp) > MAXPATHLEN)
+	if (strlen(tmp) >= MAXPATHLEN) {
+		free(tmp);
 		return false;
+	}
 	strcpy(result, tmp);
 	baselen = strlen(result);
 	free(tmp);
-- 
1.8.5.3



More information about the lxc-devel mailing list