From 6556417fa407074368a0b959fd478b8816d7c796 Mon Sep 17 00:00:00 2001
From: wujing <wujing50@huawei.com>
Date: Wed, 18 Dec 2019 15:44:19 +0800
Subject: [PATCH 131/131] fix commands and terminal memory leak bug

Signed-off-by: wujing <wujing50@huawei.com>
---
 src/lxc/commands.c | 5 ++++-
 src/lxc/terminal.c | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/lxc/commands.c b/src/lxc/commands.c
index 7d6cf6f3..b70564fd 100644
--- a/src/lxc/commands.c
+++ b/src/lxc/commands.c
@@ -1083,8 +1083,11 @@ int lxc_cmd_set_terminal_fifos(const char *name, const char *lxcpath, const char
 	if (tmp == NULL)
 		return -1;
 	ret = snprintf(tmp, len, "%s%s%s%s%s", cmd_in_fifo, split, cmd_out_fifo, split, cmd_err_fifo);
-	if (ret < 0 || ret >= len)
+	if (ret < 0 || ret >= len) {
+		ERROR("Failed to snprintf in fifo of command");
+		free(tmp);
 		return -1;
+	}
 
 	struct lxc_cmd_rr cmd = {
 		.req = {
diff --git a/src/lxc/terminal.c b/src/lxc/terminal.c
index b547013c..bccc23d9 100644
--- a/src/lxc/terminal.c
+++ b/src/lxc/terminal.c
@@ -243,6 +243,7 @@ static int lxc_terminal_rename_old_log_file(struct lxc_terminal *terminal)
 	for (i = terminal->log_rotate - 1; i > 1; i--) {
 		ret = snprintf(tmp, PATH_MAX, "%s.%u", terminal->log_path, i);
 		if (ret < 0 || ret >= PATH_MAX) {
+			free(rename_fname);
 			return -EFBIG;
 		}
 		free(rename_fname);
-- 
2.23.0

