]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/qemu-xen-traditional.git/commitdiff
block-vvfat: fix memory/handle leaks in commit_one_file()
authorKaifeng Zhu <kaifeng.zhu@citrix.com>
Fri, 7 Mar 2014 16:44:33 +0000 (16:44 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 16 Oct 2015 15:52:06 +0000 (16:52 +0100)
Some handles and memory in commit_one_file are going to be leaked if
certain function calls failed.

Signed-off-by: Kaifeng Zhu <kaifeng.zhu@citrix.com>
Coverity-IDs: 1055918 1055919
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
block-vvfat.c

index 345d7be4073249a8aaf668b5e9999af44aa5375a..ec3363cb02b6fd422767e8bf939fcd98b2fc18d5 100644 (file)
@@ -2229,11 +2229,15 @@ static int commit_one_file(BDRVVVFATState* s,
     if (fd < 0) {
        fprintf(stderr, "Could not open %s... (%s, %d)\n", mapping->path,
                strerror(errno), errno);
+       qemu_free(cluster);
        return fd;
     }
     if (offset > 0)
-       if (lseek(fd, offset, SEEK_SET) != offset)
+       if (lseek(fd, offset, SEEK_SET) != offset) {
+           close(fd);
+           qemu_free(cluster);
            return -3;
+       }
 
     while (offset < size) {
        uint32_t c1;
@@ -2249,11 +2253,17 @@ static int commit_one_file(BDRVVVFATState* s,
        ret = vvfat_read(s->bs, cluster2sector(s, c),
            (uint8_t*)cluster, (rest_size + 0x1ff) / 0x200);
 
-       if (ret < 0)
+       if (ret < 0) {
+           close(fd);
+           qemu_free(cluster);
            return ret;
+       }
 
-       if (qemu_write_ok(fd, cluster, rest_size) < 0)
+       if (qemu_write_ok(fd, cluster, rest_size) < 0) {
+           close(fd);
+           qemu_free(cluster);
            return -2;
+       }
 
        offset += rest_size;
        c = c1;
@@ -2261,6 +2271,7 @@ static int commit_one_file(BDRVVVFATState* s,
 
     ftruncate(fd, size);
     close(fd);
+    qemu_free(cluster);
 
     return commit_mappings(s, first_cluster, dir_index);
 }