Patchwork [2/7] loader: fix a file descriptor leak

login
register
mail settings
Submitter Blue Swirl
Date Jan. 8, 2011, 6:24 p.m.
Message ID <AANLkTinQEC7WtiZ37eBSWXi=2LF3S5_N8nwFHmc-kP1Q@mail.gmail.com>
Download mbox | patch
Permalink /patch/77970/
State New
Headers show

Comments

Blue Swirl - Jan. 8, 2011, 6:24 p.m.
Fix a file descriptor leak, reported by cppcheck:
[/src/qemu/hw/loader.c:311]: (error) Resource leak: fd

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
 hw/loader.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

     if (e_ident[EI_CLASS] == ELFCLASS64) {

Patch

diff --git a/hw/loader.c b/hw/loader.c
index eb198f6..35d792e 100644
--- a/hw/loader.c
+++ b/hw/loader.c
@@ -307,8 +307,9 @@  int load_elf(const char *filename, uint64_t
(*translate_fn)(void *, uint64_t),
         target_data_order = ELFDATA2LSB;
     }

-    if (target_data_order != e_ident[EI_DATA])
-        return -1;
+    if (target_data_order != e_ident[EI_DATA]) {
+        goto fail;
+    }

     lseek(fd, 0, SEEK_SET);