Commit 88426044 authored by Yunfeng Ye's avatar Yunfeng Ye Committed by Steven Rostedt (VMware)

tools/bootconfig: Fix resource leak in apply_xbc()

Fix the @data and @fd allocations that are leaked in the error path of
apply_xbc().

Link: http://lkml.kernel.org/r/583a49c9-c27a-931d-e6c2-6f63a4b18bea@huawei.comAcked-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: default avatarYunfeng Ye <yeyunfeng@huawei.com>
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
parent 192b7993
...@@ -314,6 +314,7 @@ int apply_xbc(const char *path, const char *xbc_path) ...@@ -314,6 +314,7 @@ int apply_xbc(const char *path, const char *xbc_path)
ret = delete_xbc(path); ret = delete_xbc(path);
if (ret < 0) { if (ret < 0) {
pr_err("Failed to delete previous boot config: %d\n", ret); pr_err("Failed to delete previous boot config: %d\n", ret);
free(data);
return ret; return ret;
} }
...@@ -321,24 +322,26 @@ int apply_xbc(const char *path, const char *xbc_path) ...@@ -321,24 +322,26 @@ int apply_xbc(const char *path, const char *xbc_path)
fd = open(path, O_RDWR | O_APPEND); fd = open(path, O_RDWR | O_APPEND);
if (fd < 0) { if (fd < 0) {
pr_err("Failed to open %s: %d\n", path, fd); pr_err("Failed to open %s: %d\n", path, fd);
free(data);
return fd; return fd;
} }
/* TODO: Ensure the @path is initramfs/initrd image */ /* TODO: Ensure the @path is initramfs/initrd image */
ret = write(fd, data, size + 8); ret = write(fd, data, size + 8);
if (ret < 0) { if (ret < 0) {
pr_err("Failed to apply a boot config: %d\n", ret); pr_err("Failed to apply a boot config: %d\n", ret);
return ret; goto out;
} }
/* Write a magic word of the bootconfig */ /* Write a magic word of the bootconfig */
ret = write(fd, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN); 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); pr_err("Failed to apply a boot config magic: %d\n", ret);
return ret; goto out;
} }
out:
close(fd); close(fd);
free(data); free(data);
return 0; return ret;
} }
int usage(void) int usage(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment