]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: Add error path for virStorageBackendCreateQemuImgCmdFromVol
authorJohn Ferlan <jferlan@redhat.com>
Fri, 6 Oct 2017 16:12:38 +0000 (12:12 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Fri, 27 Oct 2017 09:31:19 +0000 (05:31 -0400)
Rather than inline the various free's and return NULL, just create
an error label.

src/storage/storage_util.c

index 4371963a53d56cb88f20b48a7455bf6f9446314f..52926adee772a5d3fe8aeee171c3898a2f4ae0ef 100644 (file)
@@ -1261,19 +1261,13 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn,
     if (info.format == VIR_STORAGE_FILE_RAW &&
         vol->target.encryption != NULL &&
         vol->target.encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) {
-        if (storageBackendCreateQemuImgSecretObject(cmd, vol, &info) < 0) {
-            VIR_FREE(info.secretAlias);
-            virCommandFree(cmd);
-            return NULL;
-        }
+        if (storageBackendCreateQemuImgSecretObject(cmd, vol, &info) < 0)
+            goto error;
         enc = &vol->target.encryption->encinfo;
     }
 
-    if (storageBackendCreateQemuImgSetOptions(cmd, imgformat, enc, info) < 0) {
-        VIR_FREE(info.secretAlias);
-        virCommandFree(cmd);
-        return NULL;
-    }
+    if (storageBackendCreateQemuImgSetOptions(cmd, imgformat, enc, info) < 0)
+        goto error;
     VIR_FREE(info.secretAlias);
 
     if (info.inputPath)
@@ -1283,6 +1277,11 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn,
         virCommandAddArgFormat(cmd, "%lluK", info.size_arg);
 
     return cmd;
+
+ error:
+    VIR_FREE(info.secretAlias);
+    virCommandFree(cmd);
+    return NULL;
 }