Skip to content

Commit 8842604

Browse files
yeyunfeng-devrostedt
authored andcommitted
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]>
1 parent 192b799 commit 8842604

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tools/bootconfig/main.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,31 +314,34 @@ int apply_xbc(const char *path, const char *xbc_path)
314314
ret = delete_xbc(path);
315315
if (ret < 0) {
316316
pr_err("Failed to delete previous boot config: %d\n", ret);
317+
free(data);
317318
return ret;
318319
}
319320

320321
/* Apply new one */
321322
fd = open(path, O_RDWR | O_APPEND);
322323
if (fd < 0) {
323324
pr_err("Failed to open %s: %d\n", path, fd);
325+
free(data);
324326
return fd;
325327
}
326328
/* TODO: Ensure the @path is initramfs/initrd image */
327329
ret = write(fd, data, size + 8);
328330
if (ret < 0) {
329331
pr_err("Failed to apply a boot config: %d\n", ret);
330-
return ret;
332+
goto out;
331333
}
332334
/* Write a magic word of the bootconfig */
333335
ret = write(fd, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN);
334336
if (ret < 0) {
335337
pr_err("Failed to apply a boot config magic: %d\n", ret);
336-
return ret;
338+
goto out;
337339
}
340+
out:
338341
close(fd);
339342
free(data);
340343

341-
return 0;
344+
return ret;
342345
}
343346

344347
int usage(void)

0 commit comments

Comments
 (0)