diff mbox

[3/5] blockdev: release resources in the error case

Message ID cf9ba716266ba977305a6813f00531dbc04a18e2.1294150511.git.quintela@redhat.com
State New
Headers show

Commit Message

Juan Quintela Jan. 4, 2011, 2:33 p.m. UTC
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 blockdev.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/blockdev.c b/blockdev.c
index da619ad..f9bb659 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -467,7 +467,7 @@  DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error)
     }
     if (!file || !*file) {
         *fatal_error = 0;
-        return NULL;
+        goto error;
     }
     if (snapshot) {
         /* always use cache=unsafe with snapshot */
@@ -481,7 +481,7 @@  DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error)
     } else if (ro == 1) {
         if (type != IF_SCSI && type != IF_VIRTIO && type != IF_FLOPPY && type != IF_NONE) {
             fprintf(stderr, "qemu: readonly flag not supported for drive with this interface\n");
-            return NULL;
+            goto error;
         }
     }

@@ -491,13 +491,16 @@  DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error)
     if (ret < 0) {
         fprintf(stderr, "qemu: could not open disk image %s: %s\n",
                         file, strerror(-ret));
-        return NULL;
+        goto error;
     }

     if (bdrv_key_required(dinfo->bdrv))
         autostart = 0;
     *fatal_error = 0;
     return dinfo;
+error:
+    drive_uninit(dinfo);
+    return NULL;
 }

 void do_commit(Monitor *mon, const QDict *qdict)