Patchwork [1/2] vvfat: avoid leaking file descriptor in commit_one_file()

login
register
mail settings
Submitter Stefan Hajnoczi
Date Jan. 6, 2012, 4:57 p.m.
Message ID <1325869065-32182-2-git-send-email-stefanha@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/134685/
State New
Headers show

Comments

Stefan Hajnoczi - Jan. 6, 2012, 4:57 p.m.
Reported-by: Dr David Alan Gilbert <davidagilbert@uk.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 block/vvfat.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

Patch

diff --git a/block/vvfat.c b/block/vvfat.c
index eeffc4a..9ef21dd 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2218,6 +2218,7 @@  static int commit_one_file(BDRVVVFATState* s,
     }
     if (offset > 0) {
         if (lseek(fd, offset, SEEK_SET) != offset) {
+            close(fd);
             g_free(cluster);
             return -3;
         }
@@ -2238,11 +2239,13 @@  static int commit_one_file(BDRVVVFATState* s,
 	    (uint8_t*)cluster, (rest_size + 0x1ff) / 0x200);
 
         if (ret < 0) {
+            close(fd);
             g_free(cluster);
             return ret;
         }
 
         if (write(fd, cluster, rest_size) < 0) {
+            close(fd);
             g_free(cluster);
             return -2;
         }