]> xenbits.xensource.com Git - libvirt.git/commitdiff
storageVolCreateXML: Swap order of two operations
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 10 Feb 2016 16:05:03 +0000 (17:05 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 12 Feb 2016 15:16:46 +0000 (16:16 +0100)
Firstly, we realloc internal list to hold new item (=volume that
will be potentially created) and then we check whether we
actually know how to create it. If we don't we consume more
memory than we really need for no good reason.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/storage/storage_driver.c

index 8ee28406f23246fa47367570d0e2f31474ad9648..e0ded0161994930a7483930516ca6aaf9a0595ad 100644 (file)
@@ -1856,10 +1856,6 @@ storageVolCreateXML(virStoragePoolPtr obj,
         goto cleanup;
     }
 
-    if (VIR_REALLOC_N(pool->volumes.objs,
-                      pool->volumes.count+1) < 0)
-        goto cleanup;
-
     if (!backend->createVol) {
         virReportError(VIR_ERR_NO_SUPPORT,
                        "%s", _("storage pool does not support volume "
@@ -1867,6 +1863,10 @@ storageVolCreateXML(virStoragePoolPtr obj,
         goto cleanup;
     }
 
+    if (VIR_REALLOC_N(pool->volumes.objs,
+                      pool->volumes.count+1) < 0)
+        goto cleanup;
+
     /* Wipe any key the user may have suggested, as volume creation
      * will generate the canonical key.  */
     VIR_FREE(voldef->key);