Commit 265ca29a7162a9437efabdb3b133237eef49ab7b

Authored by aliguori
1 parent 3adae656

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
Showing 1 changed file with 10 additions and 9 deletions
loader.c
... ... @@ -354,6 +354,7 @@ int load_uboot(const char *filename, target_ulong *ep, int *is_linux)
354 354 uboot_image_header_t h;
355 355 uboot_image_header_t *hdr = &h;
356 356 uint8_t *data = NULL;
  357 + int ret = -1;
357 358  
358 359 fd = open(filename, O_RDONLY | O_BINARY);
359 360 if (fd < 0)
... ... @@ -361,23 +362,23 @@ int load_uboot(const char *filename, target_ulong *ep, int *is_linux)
361 362  
362 363 size = read(fd, hdr, sizeof(uboot_image_header_t));
363 364 if (size < 0)
364   - goto fail;
  365 + goto out;
365 366  
366 367 bswap_uboot_header(hdr);
367 368  
368 369 if (hdr->ih_magic != IH_MAGIC)
369   - goto fail;
  370 + goto out;
370 371  
371 372 /* TODO: Implement Multi-File images. */
372 373 if (hdr->ih_type == IH_TYPE_MULTI) {
373 374 fprintf(stderr, "Unable to load multi-file u-boot images\n");
374   - goto fail;
  375 + goto out;
375 376 }
376 377  
377 378 /* TODO: Implement compressed images. */
378 379 if (hdr->ih_comp != IH_COMP_NONE) {
379 380 fprintf(stderr, "Unable to load compressed u-boot images\n");
380   - goto fail;
  381 + goto out;
381 382 }
382 383  
383 384 /* TODO: Check CPU type. */
... ... @@ -391,20 +392,20 @@ int load_uboot(const char *filename, target_ulong *ep, int *is_linux)
391 392 *ep = hdr->ih_ep;
392 393 data = qemu_malloc(hdr->ih_size);
393 394 if (!data)
394   - goto fail;
  395 + goto out;
395 396  
396 397 if (read(fd, data, hdr->ih_size) != hdr->ih_size) {
397 398 fprintf(stderr, "Error reading file\n");
398   - goto fail;
  399 + goto out;
399 400 }
400 401  
401 402 cpu_physical_memory_write_rom(hdr->ih_load, data, hdr->ih_size);
402 403  
403   - return hdr->ih_size;
  404 + ret = hdr->ih_size;
404 405  
405   -fail:
  406 +out:
406 407 if (data)
407 408 qemu_free(data);
408 409 close(fd);
409   - return -1;
  410 + return ret;
410 411 }
... ...