diff options
author | Zhang Yanfei <zhangyanfei@cn.fujitsu.com> | 2013-03-25 23:15:00 +0800 |
---|---|---|
committer | Simon Horman <horms@verge.net.au> | 2013-03-27 21:41:00 +0900 |
commit | 14865de2ea698d1a4a83e90d78437e9309db73e9 (patch) | |
tree | 87e9fb12f2c4e729089833da45bdf528417dae40 | |
parent | e640d91329a3a227476fa0a1355b07291c2dac3d (diff) | |
download | kexec-tools-14865de2ea698d1a4a83e90d78437e9309db73e9.tar.gz |
kexec: ppc: uImage: fix possible memory leak in ppc_load_bare_bits
In ppc_load_bare_bits, allocated memory may not be free'd if the code
exits abnormally, by calling die() or return. So the patch fixes
the possible memory leak.
This patch is also a preparation for patch10.
Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Simon Horman <horms@verge.net.au>
-rw-r--r-- | kexec/arch/ppc/kexec-uImage-ppc.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/kexec/arch/ppc/kexec-uImage-ppc.c b/kexec/arch/ppc/kexec-uImage-ppc.c index 900cd166..fd8959c4 100644 --- a/kexec/arch/ppc/kexec-uImage-ppc.c +++ b/kexec/arch/ppc/kexec-uImage-ppc.c @@ -90,13 +90,14 @@ static int ppc_load_bare_bits(int argc, char **argv, const char *buf, char *fixup_nodes[FIXUP_ENTRYS + 1]; int cur_fixup = 0; int opt; - int ret; + int ret = 0; char *seg_buf = NULL; off_t seg_size = 0; unsigned long long hole_addr; unsigned long max_addr; char *blob_buf = NULL; off_t blob_size = 0; + char *error_msg = NULL; cmdline_buf = NULL; command_line = NULL; @@ -186,7 +187,8 @@ static int ppc_load_bare_bits(int argc, char **argv, const char *buf, ret = load_crashdump_segments(info, crash_cmdline, max_addr, 0); if (ret < 0) { - return -1; + ret = -1; + goto out; } } @@ -212,8 +214,10 @@ static int ppc_load_bare_bits(int argc, char **argv, const char *buf, create_flatten_tree(info, (unsigned char **)&blob_buf, (unsigned long *)&blob_size, cmdline_buf); } - if (!blob_buf || !blob_size) - die("Device tree seems to be an empty file.\n"); + if (!blob_buf || !blob_size) { + error_msg = "Device tree seems to be an empty file.\n"; + goto out2; + } /* initial fixup for device tree */ blob_buf = fixup_dtb_init(info, blob_buf, &blob_size, load_addr, &dtb_addr); @@ -249,7 +253,8 @@ static int ppc_load_bare_bits(int argc, char **argv, const char *buf, load_addr + KERNEL_ACCESS_TOP, 1); if (dtb_addr_actual != dtb_addr) { printf("dtb_addr_actual: %lx, dtb_addr: %lx\n", dtb_addr_actual, dtb_addr); - die("Error device tree not loadded to address it was expecting to be loaded too!\n"); + error_msg = "Error device tree not loadded to address it was expecting to be loaded too!\n"; + goto out2; } /* set various variables for the purgatory */ @@ -286,7 +291,13 @@ static int ppc_load_bare_bits(int argc, char **argv, const char *buf, addr = elf_rel_get_addr(&info->rhdr, "purgatory_start"); info->entry = (void *)addr; - return 0; +out2: + free(cmdline_buf); +out: + free(crash_cmdline); + if (error_msg) + die(error_msg); + return ret; } int uImage_ppc_load(int argc, char **argv, const char *buf, off_t len, |