Patchwork [1/2] fix fd leak on one qcow2_create2() error path

login
register
mail settings
Submitter Eduardo Habkost
Date Oct. 7, 2010, 8:25 p.m.
Message ID <1286483105-9768-2-git-send-email-ehabkost@redhat.com>
Download mbox | patch
Permalink /patch/67106/
State New
Headers show

Comments

Eduardo Habkost - Oct. 7, 2010, 8:25 p.m.
When getting an invalid cluster size, the open fd must be closed before
qcow2_create() returns an error.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 block/qcow2.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
Stefan Hajnoczi - Oct. 8, 2010, 9:36 a.m.
On Thu, Oct 7, 2010 at 9:25 PM, Eduardo Habkost <ehabkost@redhat.com> wrote:
> When getting an invalid cluster size, the open fd must be closed before
> qcow2_create() returns an error.
>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  block/qcow2.c |    5 ++++-
>  1 files changed, 4 insertions(+), 1 deletions(-)

Looks good.

Stefan

Patch

diff --git a/block/qcow2.c b/block/qcow2.c
index ee3481b..c5fb28e 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -918,7 +918,8 @@  static int qcow_create2(const char *filename, int64_t total_size,
             "%d and %dk\n",
             1 << MIN_CLUSTER_BITS,
             1 << (MAX_CLUSTER_BITS - 10));
-        return -EINVAL;
+        ret = -EINVAL;
+        goto exit_close;
     }
     s->cluster_size = 1 << s->cluster_bits;
 
@@ -1052,6 +1053,8 @@  static int qcow_create2(const char *filename, int64_t total_size,
 exit:
     qemu_free(s->refcount_table);
     qemu_free(s->refcount_block);
+
+exit_close:
     close(fd);
 
     /* Preallocate metadata */