mirror of
https://github.com/torvalds/linux.git
synced 2026-10-07 22:37:45 -04:00
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/[email protected] Acked-by: Masami Hiramatsu <[email protected]> Signed-off-by: Yunfeng Ye <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
This commit is contained in:
1 parent
192b7993b3
commit
8842604446
1 file changed
+6
-3
@@ -314,6 +314,7 @@ 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);
|
||||
free(data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -321,24 +322,26 @@ int apply_xbc(const char *path, const char *xbc_path)
|
||||
fd = open(path, O_RDWR | O_APPEND);
|
||||
if (fd < 0) {
|
||||
pr_err("Failed to open %s: %d\n", path, fd);
|
||||
free(data);
|
||||
return fd;
|
||||
}
|
||||
/* 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 out;
|
||||
}
|
||||
/* Write a magic word of the bootconfig */
|
||||
ret = write(fd, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN);
|
||||
if (ret < 0) {
|
||||
pr_err("Failed to apply a boot config magic: %d\n", ret);
|
||||
return ret;
|
||||
goto out;
|
||||
}
|
||||
out:
|
||||
close(fd);
|
||||
free(data);
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int usage(void)
|
||||
|
||||
Reference in new issue
Block a user