summaryrefslogtreecommitdiff
path: root/loader.c
diff options
context:
space:
mode:
authoraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2008-11-20 22:02:56 +0000
committeraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2008-11-20 22:02:56 +0000
commit10f84a8fa3282b9e50293ad93c2947994d077adf (patch)
tree7fa4481ae125c9890f89c48458810ec82e527988 /loader.c
parentd7194c4cce63decf09eabf98dc14017fb153464e (diff)
downloadqemu-10f84a8fa3282b9e50293ad93c2947994d077adf.tar.gz
qemu-10f84a8fa3282b9e50293ad93c2947994d077adf.tar.bz2
qemu-10f84a8fa3282b9e50293ad93c2947994d077adf.zip
uImage: don't leak file data or file descriptor (Hollis Blanchard)
Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5761 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'loader.c')
-rw-r--r--loader.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/loader.c b/loader.c
index 872290957c..e7e6abcbbd 100644
--- a/loader.c
+++ b/loader.c
@@ -354,6 +354,7 @@ int load_uboot(const char *filename, target_ulong *ep, int *is_linux)
uboot_image_header_t h;
uboot_image_header_t *hdr = &h;
uint8_t *data = NULL;
+ int ret = -1;
fd = open(filename, O_RDONLY | O_BINARY);
if (fd < 0)
@@ -361,23 +362,23 @@ int load_uboot(const char *filename, target_ulong *ep, int *is_linux)
size = read(fd, hdr, sizeof(uboot_image_header_t));
if (size < 0)
- goto fail;
+ goto out;
bswap_uboot_header(hdr);
if (hdr->ih_magic != IH_MAGIC)
- goto fail;
+ goto out;
/* TODO: Implement Multi-File images. */
if (hdr->ih_type == IH_TYPE_MULTI) {
fprintf(stderr, "Unable to load multi-file u-boot images\n");
- goto fail;
+ goto out;
}
/* TODO: Implement compressed images. */
if (hdr->ih_comp != IH_COMP_NONE) {
fprintf(stderr, "Unable to load compressed u-boot images\n");
- goto fail;
+ goto out;
}
/* TODO: Check CPU type. */
@@ -391,20 +392,20 @@ int load_uboot(const char *filename, target_ulong *ep, int *is_linux)
*ep = hdr->ih_ep;
data = qemu_malloc(hdr->ih_size);
if (!data)
- goto fail;
+ goto out;
if (read(fd, data, hdr->ih_size) != hdr->ih_size) {
fprintf(stderr, "Error reading file\n");
- goto fail;
+ goto out;
}
cpu_physical_memory_write_rom(hdr->ih_load, data, hdr->ih_size);
- return hdr->ih_size;
+ ret = hdr->ih_size;
-fail:
+out:
if (data)
qemu_free(data);
close(fd);
- return -1;
+ return ret;
}