|
|
9ae3a8 |
From 631c132d062d057d4648c88e5dfa4b8a375d3442 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
Date: Mon, 4 Nov 2013 22:31:56 +0100
|
|
|
9ae3a8 |
Subject: [PATCH 03/87] block: fix vvfat error path for enable_write_target
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1383604354-12743-6-git-send-email-mreitz@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 55305
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.0 qemu-kvm PATCH 05/43] block: fix vvfat error path for enable_write_target
|
|
|
9ae3a8 |
Bugzilla: 1026524
|
|
|
9ae3a8 |
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
From: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
BZ: 1026524
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
s->qcow and s->qcow_filename are allocated but not freed on error. Fix the
|
|
|
9ae3a8 |
possible leaks, remove unnecessary check for bdrv_new(), propagate ret code of
|
|
|
9ae3a8 |
bdrv_create() and also the one of enable_write_target().
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit 78f27bd02ceba4a2f6ac5c725f4d4410eec205ef)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block/vvfat.c | 25 ++++++++++++++-----------
|
|
|
9ae3a8 |
1 file changed, 14 insertions(+), 11 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block/vvfat.c | 25 ++++++++++++++-----------
|
|
|
9ae3a8 |
1 files changed, 14 insertions(+), 11 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block/vvfat.c b/block/vvfat.c
|
|
|
9ae3a8 |
index 415fba3..dd0efca 100644
|
|
|
9ae3a8 |
--- a/block/vvfat.c
|
|
|
9ae3a8 |
+++ b/block/vvfat.c
|
|
|
9ae3a8 |
@@ -1164,8 +1164,8 @@ DLOG(if (stderr == NULL) {
|
|
|
9ae3a8 |
s->sector_count = cyls * heads * secs - (s->first_sectors_number - 1);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (qemu_opt_get_bool(opts, "rw", false)) {
|
|
|
9ae3a8 |
- if (enable_write_target(s)) {
|
|
|
9ae3a8 |
- ret = -EIO;
|
|
|
9ae3a8 |
+ ret = enable_write_target(s);
|
|
|
9ae3a8 |
+ if (ret < 0) {
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
bs->read_only = 0;
|
|
|
9ae3a8 |
@@ -2918,9 +2918,7 @@ static int enable_write_target(BDRVVVFATState *s)
|
|
|
9ae3a8 |
s->qcow_filename = g_malloc(1024);
|
|
|
9ae3a8 |
ret = get_tmp_filename(s->qcow_filename, 1024);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
- g_free(s->qcow_filename);
|
|
|
9ae3a8 |
- s->qcow_filename = NULL;
|
|
|
9ae3a8 |
- return ret;
|
|
|
9ae3a8 |
+ goto err;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
bdrv_qcow = bdrv_find_format("qcow");
|
|
|
9ae3a8 |
@@ -2928,18 +2926,18 @@ static int enable_write_target(BDRVVVFATState *s)
|
|
|
9ae3a8 |
set_option_parameter_int(options, BLOCK_OPT_SIZE, s->sector_count * 512);
|
|
|
9ae3a8 |
set_option_parameter(options, BLOCK_OPT_BACKING_FILE, "fat:");
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- if (bdrv_create(bdrv_qcow, s->qcow_filename, options) < 0)
|
|
|
9ae3a8 |
- return -1;
|
|
|
9ae3a8 |
+ ret = bdrv_create(bdrv_qcow, s->qcow_filename, options);
|
|
|
9ae3a8 |
+ if (ret < 0) {
|
|
|
9ae3a8 |
+ goto err;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
s->qcow = bdrv_new("");
|
|
|
9ae3a8 |
- if (s->qcow == NULL) {
|
|
|
9ae3a8 |
- return -1;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
ret = bdrv_open(s->qcow, s->qcow_filename, NULL,
|
|
|
9ae3a8 |
BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, bdrv_qcow);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
- return ret;
|
|
|
9ae3a8 |
+ bdrv_delete(s->qcow);
|
|
|
9ae3a8 |
+ goto err;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
#ifndef _WIN32
|
|
|
9ae3a8 |
@@ -2952,6 +2950,11 @@ static int enable_write_target(BDRVVVFATState *s)
|
|
|
9ae3a8 |
*(void**)s->bs->backing_hd->opaque = s;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
return 0;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+err:
|
|
|
9ae3a8 |
+ g_free(s->qcow_filename);
|
|
|
9ae3a8 |
+ s->qcow_filename = NULL;
|
|
|
9ae3a8 |
+ return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static void vvfat_close(BlockDriverState *bs)
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.1
|
|
|
9ae3a8 |
|