[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <189d719f-a8b8-6e10-ae2f-8120c3d2b7a9@huawei.com>
Date: Fri, 8 May 2020 14:51:15 +0800
From: Yunfeng Ye <yeyunfeng@...wei.com>
To: <mhiramat@...nel.org>, <rostedt@...dmis.org>,
<linux-kernel@...r.kernel.org>, <Markus.Elfring@....de>,
<rostedt@...dmis.org>, <kernel-janitors@...r.kernel.org>,
Shiyuan Hu <hushiyuan@...wei.com>,
Hewenliang <hewenliang4@...wei.com>
Subject: [PATCH v2] tools/bootconfig: fix resource leak in apply_xbc()
Fix the @data and @fd allocations that are leaked in the error path of
apply_xbc().
Fixes: 85c46b78da58 ("bootconfig: Add bootconfig magic word for indicating bootconfig explicitly")
Fixes: 950313ebf79c ("tools: bootconfig: Add bootconfig command")
Acked-by: Masami Hiramatsu <mhiramat@...nel.org>
Signed-off-by: Yunfeng Ye <yeyunfeng@...wei.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@...dmis.org>
---
tools/bootconfig/main.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c
index 16b9a420e6fd..d034f86022b7 100644
--- a/tools/bootconfig/main.c
+++ b/tools/bootconfig/main.c
@@ -314,31 +314,33 @@ int apply_xbc(const char *path, const char *xbc_path)
ret = delete_xbc(path);
if (ret < 0) {
pr_err("Failed to delete previous boot config: %d\n", ret);
- return ret;
+ goto free_data;
}
/* Apply new one */
fd = open(path, O_RDWR | O_APPEND);
if (fd < 0) {
pr_err("Failed to open %s: %d\n", path, fd);
- return fd;
+ ret = fd;
+ goto free_data;
}
/* TODO: Ensure the @path is initramfs/initrd image */
ret = write(fd, data, size + 8);
if (ret < 0) {
pr_err("Failed to apply a boot config: %d\n", ret);
- return ret;
+ goto close_fd;
}
/* Write a magic word of the bootconfig */
ret = write(fd, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN);
- if (ret < 0) {
+ if (ret < 0)
pr_err("Failed to apply a boot config magic: %d\n", ret);
- return ret;
- }
+
+close_fd:
close(fd);
+free_data:
free(data);
- return 0;
+ return ret;
}
int usage(void)
--
1.8.3.1
Powered by blists - more mailing lists