[PATCH 03/15] conf: Introduce VIR_DEFINE_AUTOPTR_FUNC for virStorageVolDef

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Let's make use of the auto __cleanup capabilities cleaning up any
now unnecessary goto paths. For virStorageVolDefParseXML use the
@def/@ret similarly as other methods.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/conf/storage_conf.c                    | 112 ++++++++++-----------
 src/conf/storage_conf.h                    |   1 +
 src/esx/esx_storage_backend_vmfs.c         |   6 +-
 src/phyp/phyp_driver.c                     |   3 +-
 src/storage/storage_backend_gluster.c      |   9 +-
 src/storage/storage_backend_iscsi_direct.c |  19 ++--
 src/storage/storage_backend_mpath.c        |  24 ++---
 src/storage/storage_backend_rbd.c          |   9 +-
 src/storage/storage_backend_sheepdog.c     |  15 ++-
 src/storage/storage_driver.c               |   6 +-
 src/storage/storage_util.c                 |   6 +-
 src/test/test_driver.c                     |  10 +-
 src/vbox/vbox_storage.c                    |   3 +-
 tests/storagebackendsheepdogtest.c         |   3 +-
 tests/storagevolxml2argvtest.c             |   5 +-
 tests/storagevolxml2xmltest.c              |   3 +-
 16 files changed, 100 insertions(+), 134 deletions(-)

diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 6099c64b26..83ca379217 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1168,7 +1168,8 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
                          xmlXPathContextPtr ctxt,
                          unsigned int flags)
 {
-    virStorageVolDefPtr ret;
+    VIR_AUTOPTR(virStorageVolDef) def = NULL;
+    virStorageVolDefPtr ret = NULL;
     virStorageVolOptionsPtr options;
     char *type = NULL;
     char *allocation = NULL;
@@ -1187,132 +1188,132 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
     if (options == NULL)
         return NULL;
 
-    if (VIR_ALLOC(ret) < 0)
+    if (VIR_ALLOC(def) < 0)
         return NULL;
 
-    ret->target.type = VIR_STORAGE_TYPE_FILE;
+    def->target.type = VIR_STORAGE_TYPE_FILE;
 
-    ret->name = virXPathString("string(./name)", ctxt);
-    if (ret->name == NULL) {
+    def->name = virXPathString("string(./name)", ctxt);
+    if (def->name == NULL) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("missing volume name element"));
-        goto error;
+        goto cleanup;
     }
 
     /* Normally generated by pool refresh, but useful for unit tests */
-    ret->key = virXPathString("string(./key)", ctxt);
+    def->key = virXPathString("string(./key)", ctxt);
 
     /* Technically overridden by pool refresh, but useful for unit tests */
     type = virXPathString("string(./@type)", ctxt);
     if (type) {
-        if ((ret->type = virStorageVolTypeFromString(type)) < 0) {
+        if ((def->type = virStorageVolTypeFromString(type)) < 0) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("unknown volume type '%s'"), type);
-            goto error;
+            goto cleanup;
         }
     }
 
     if ((backingStore = virXPathString("string(./backingStore/path)", ctxt))) {
-        if (VIR_ALLOC(ret->target.backingStore) < 0)
-            goto error;
+        if (VIR_ALLOC(def->target.backingStore) < 0)
+            goto cleanup;
 
-        ret->target.backingStore->type = VIR_STORAGE_TYPE_FILE;
+        def->target.backingStore->type = VIR_STORAGE_TYPE_FILE;
 
-        ret->target.backingStore->path = backingStore;
+        def->target.backingStore->path = backingStore;
         backingStore = NULL;
 
         if (options->formatFromString) {
             char *format = virXPathString("string(./backingStore/format/@type)", ctxt);
             if (format == NULL)
-                ret->target.backingStore->format = options->defaultFormat;
+                def->target.backingStore->format = options->defaultFormat;
             else
-                ret->target.backingStore->format = (options->formatFromString)(format);
+                def->target.backingStore->format = (options->formatFromString)(format);
 
-            if (ret->target.backingStore->format < 0) {
+            if (def->target.backingStore->format < 0) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                                _("unknown volume format type %s"), format);
                 VIR_FREE(format);
-                goto error;
+                goto cleanup;
             }
             VIR_FREE(format);
         }
 
-        if (VIR_ALLOC(ret->target.backingStore->perms) < 0)
-            goto error;
-        if (virStorageDefParsePerms(ctxt, ret->target.backingStore->perms,
+        if (VIR_ALLOC(def->target.backingStore->perms) < 0)
+            goto cleanup;
+        if (virStorageDefParsePerms(ctxt, def->target.backingStore->perms,
                                     "./backingStore/permissions") < 0)
-            goto error;
+            goto cleanup;
     }
 
     capacity = virXPathString("string(./capacity)", ctxt);
     unit = virXPathString("string(./capacity/@unit)", ctxt);
     if (capacity) {
-        if (virStorageSize(unit, capacity, &ret->target.capacity) < 0)
-            goto error;
+        if (virStorageSize(unit, capacity, &def->target.capacity) < 0)
+            goto cleanup;
     } else if (!(flags & VIR_VOL_XML_PARSE_NO_CAPACITY) &&
                !((flags & VIR_VOL_XML_PARSE_OPT_CAPACITY) &&
-                 virStorageSourceHasBacking(&ret->target))) {
+                 virStorageSourceHasBacking(&def->target))) {
         virReportError(VIR_ERR_XML_ERROR, "%s", _("missing capacity element"));
-        goto error;
+        goto cleanup;
     }
     VIR_FREE(unit);
 
     allocation = virXPathString("string(./allocation)", ctxt);
     if (allocation) {
         unit = virXPathString("string(./allocation/@unit)", ctxt);
-        if (virStorageSize(unit, allocation, &ret->target.allocation) < 0)
-            goto error;
-        ret->target.has_allocation = true;
+        if (virStorageSize(unit, allocation, &def->target.allocation) < 0)
+            goto cleanup;
+        def->target.has_allocation = true;
     } else {
-        ret->target.allocation = ret->target.capacity;
+        def->target.allocation = def->target.capacity;
     }
 
-    ret->target.path = virXPathString("string(./target/path)", ctxt);
+    def->target.path = virXPathString("string(./target/path)", ctxt);
     if (options->formatFromString) {
         char *format = virXPathString("string(./target/format/@type)", ctxt);
         if (format == NULL)
-            ret->target.format = options->defaultFormat;
+            def->target.format = options->defaultFormat;
         else
-            ret->target.format = (options->formatFromString)(format);
+            def->target.format = (options->formatFromString)(format);
 
-        if (ret->target.format < 0) {
+        if (def->target.format < 0) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("unknown volume format type %s"), format);
             VIR_FREE(format);
-            goto error;
+            goto cleanup;
         }
         VIR_FREE(format);
     }
 
-    if (VIR_ALLOC(ret->target.perms) < 0)
-        goto error;
-    if (virStorageDefParsePerms(ctxt, ret->target.perms,
+    if (VIR_ALLOC(def->target.perms) < 0)
+        goto cleanup;
+    if (virStorageDefParsePerms(ctxt, def->target.perms,
                                 "./target/permissions") < 0)
-        goto error;
+        goto cleanup;
 
     node = virXPathNode("./target/encryption", ctxt);
     if (node != NULL) {
-        ret->target.encryption = virStorageEncryptionParseNode(node, ctxt);
-        if (ret->target.encryption == NULL)
-            goto error;
+        def->target.encryption = virStorageEncryptionParseNode(node, ctxt);
+        if (def->target.encryption == NULL)
+            goto cleanup;
     }
 
-    ret->target.compat = virXPathString("string(./target/compat)", ctxt);
-    if (virStorageFileCheckCompat(ret->target.compat) < 0)
-        goto error;
+    def->target.compat = virXPathString("string(./target/compat)", ctxt);
+    if (virStorageFileCheckCompat(def->target.compat) < 0)
+        goto cleanup;
 
     if (virXPathNode("./target/nocow", ctxt))
-        ret->target.nocow = true;
+        def->target.nocow = true;
 
     if (virXPathNode("./target/features", ctxt)) {
         if ((n = virXPathNodeSet("./target/features/*", ctxt, &nodes)) < 0)
-            goto error;
+            goto cleanup;
 
-        if (!ret->target.compat && VIR_STRDUP(ret->target.compat, "1.1") < 0)
-            goto error;
+        if (!def->target.compat && VIR_STRDUP(def->target.compat, "1.1") < 0)
+            goto cleanup;
 
-        if (!(ret->target.features = virBitmapNew(VIR_STORAGE_FILE_FEATURE_LAST)))
-            goto error;
+        if (!(def->target.features = virBitmapNew(VIR_STORAGE_FILE_FEATURE_LAST)))
+            goto cleanup;
 
         for (i = 0; i < n; i++) {
             int f = virStorageFileFeatureTypeFromString((const char*)nodes[i]->name);
@@ -1320,13 +1321,15 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
             if (f < 0) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unsupported feature %s"),
                                (const char*)nodes[i]->name);
-                goto error;
+                goto cleanup;
             }
-            ignore_value(virBitmapSetBit(ret->target.features, f));
+            ignore_value(virBitmapSetBit(def->target.features, f));
         }
         VIR_FREE(nodes);
     }
 
+    VIR_STEAL_PTR(ret, def);
+
  cleanup:
     VIR_FREE(nodes);
     VIR_FREE(allocation);
@@ -1335,11 +1338,6 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
     VIR_FREE(type);
     VIR_FREE(backingStore);
     return ret;
-
- error:
-    virStorageVolDefFree(ret);
-    ret = NULL;
-    goto cleanup;
 }
 
 
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index 3fa97bba76..b8e73864c4 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -461,5 +461,6 @@ VIR_ENUM_DECL(virStoragePartedFs);
                  VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_POOL_TYPE)
 
 VIR_DEFINE_AUTOPTR_FUNC(virStoragePoolSource, virStoragePoolSourceFree);
+VIR_DEFINE_AUTOPTR_FUNC(virStorageVolDef, virStorageVolDefFree);
 
 #endif /* LIBVIRT_STORAGE_CONF_H */
diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backend_vmfs.c
index 8458d4e95c..6e1c3c0285 100644
--- a/src/esx/esx_storage_backend_vmfs.c
+++ b/src/esx/esx_storage_backend_vmfs.c
@@ -836,7 +836,7 @@ esxStorageVolCreateXML(virStoragePoolPtr pool,
     virStorageVolPtr volume = NULL;
     esxPrivate *priv = pool->conn->privateData;
     virStoragePoolDef poolDef;
-    virStorageVolDefPtr def = NULL;
+    VIR_AUTOPTR(virStorageVolDef) def = NULL;
     char *tmp;
     char *unescapedDatastorePath = NULL;
     char *unescapedDirectoryName = NULL;
@@ -1024,7 +1024,6 @@ esxStorageVolCreateXML(virStoragePoolPtr pool,
         virtualDiskSpec->adapterType = NULL;
     }
 
-    virStorageVolDefFree(def);
     VIR_FREE(unescapedDatastorePath);
     VIR_FREE(unescapedDirectoryName);
     VIR_FREE(unescapedDirectoryAndFileName);
@@ -1054,7 +1053,7 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool,
     esxPrivate *priv = pool->conn->privateData;
     virStoragePoolDef poolDef;
     char *sourceDatastorePath = NULL;
-    virStorageVolDefPtr def = NULL;
+    VIR_AUTOPTR(virStorageVolDef) def = NULL;
     char *tmp;
     char *unescapedDatastorePath = NULL;
     char *unescapedDirectoryName = NULL;
@@ -1207,7 +1206,6 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool,
 
  cleanup:
     VIR_FREE(sourceDatastorePath);
-    virStorageVolDefFree(def);
     VIR_FREE(unescapedDatastorePath);
     VIR_FREE(unescapedDirectoryName);
     VIR_FREE(unescapedDirectoryAndFileName);
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index 4ffa08ff43..966e0b3c0f 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -1952,7 +1952,7 @@ phypStorageVolCreateXML(virStoragePoolPtr pool,
 {
     virCheckFlags(0, NULL);
 
-    virStorageVolDefPtr voldef = NULL;
+    VIR_AUTOPTR(virStorageVolDef) voldef = NULL;
     virStoragePoolDefPtr spdef = NULL;
     virStorageVolPtr vol = NULL;
     virStorageVolPtr dup_vol = NULL;
@@ -2036,7 +2036,6 @@ phypStorageVolCreateXML(virStoragePoolPtr pool,
 
  err:
     VIR_FREE(key);
-    virStorageVolDefFree(voldef);
     virStoragePoolDefFree(spdef);
     virObjectUnref(vol);
     return NULL;
diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_backend_gluster.c
index 8c6205b081..cb9f7e4735 100644
--- a/src/storage/storage_backend_gluster.c
+++ b/src/storage/storage_backend_gluster.c
@@ -242,7 +242,7 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
                                    virStorageVolDefPtr *volptr)
 {
     int ret = -1;
-    virStorageVolDefPtr vol = NULL;
+    VIR_AUTOPTR(virStorageVolDef) vol = NULL;
     glfs_fd_t *fd = NULL;
     virStorageSourcePtr meta = NULL;
     char *header = NULL;
@@ -278,8 +278,7 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
     if (S_ISDIR(st->st_mode)) {
         vol->type = VIR_STORAGE_VOL_NETDIR;
         vol->target.format = VIR_STORAGE_FILE_DIR;
-        *volptr = vol;
-        vol = NULL;
+        VIR_STEAL_PTR(*volptr, vol);
         ret = 0;
         goto cleanup;
     }
@@ -328,12 +327,10 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
     vol->target.compat = meta->compat;
     meta->compat = NULL;
 
-    *volptr = vol;
-    vol = NULL;
+    VIR_STEAL_PTR(*volptr, vol);
     ret = 0;
  cleanup:
     virStorageSourceFree(meta);
-    virStorageVolDefFree(vol);
     if (fd)
         glfs_close(fd);
     VIR_FREE(header);
diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/storage_backend_iscsi_direct.c
index ddc150f03d..f287fbf010 100644
--- a/src/storage/storage_backend_iscsi_direct.c
+++ b/src/storage/storage_backend_iscsi_direct.c
@@ -305,22 +305,21 @@ virISCSIDirectRefreshVol(virStoragePoolObjPtr pool,
                          char *portal)
 {
     virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
-    virStorageVolDefPtr vol = NULL;
+    VIR_AUTOPTR(virStorageVolDef) vol = NULL;
     uint32_t block_size;
     uint32_t nb_block;
-    int ret = -1;
 
     virStoragePoolObjClearVols(pool);
     if (virISCSIDirectTestUnitReady(iscsi, lun) < 0)
-        goto cleanup;
+        return -1;
 
     if (VIR_ALLOC(vol) < 0)
-        goto cleanup;
+        return -1;
 
     vol->type = VIR_STORAGE_VOL_NETWORK;
 
     if (virISCSIDirectGetVolumeCapacity(iscsi, lun, &block_size, &nb_block) < 0)
-        goto cleanup;
+        return -1;
 
     vol->target.capacity = block_size * nb_block;
     vol->target.allocation = block_size * nb_block;
@@ -328,17 +327,13 @@ virISCSIDirectRefreshVol(virStoragePoolObjPtr pool,
     def->allocation += vol->target.allocation;
 
     if (virISCSIDirectSetVolumeAttributes(pool, vol, lun, portal) < 0)
-        goto cleanup;
+        return -1;
 
     if (virStoragePoolObjAddVol(pool, vol) < 0)
-        goto cleanup;
-
+        return -1;
     vol = NULL;
 
-    ret = 0;
- cleanup:
-    virStorageVolDefFree(vol);
-    return ret;
+    return 0;
 }
 
 static int
diff --git a/src/storage/storage_backend_mpath.c b/src/storage/storage_backend_mpath.c
index b3a49ee1b2..423f945fbc 100644
--- a/src/storage/storage_backend_mpath.c
+++ b/src/storage/storage_backend_mpath.c
@@ -46,42 +46,36 @@ virStorageBackendMpathNewVol(virStoragePoolObjPtr pool,
                              const char *dev)
 {
     virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
-    virStorageVolDefPtr vol;
-    int ret = -1;
+    VIR_AUTOPTR(virStorageVolDef) vol = NULL;
 
     if (VIR_ALLOC(vol) < 0)
-        goto cleanup;
+        return -1;
 
     vol->type = VIR_STORAGE_VOL_BLOCK;
 
     if (virAsprintf(&(vol->name), "dm-%u", devnum) < 0)
-        goto cleanup;
+        return -1;
 
     if (virAsprintf(&vol->target.path, "/dev/%s", dev) < 0)
-        goto cleanup;
+        return -1;
 
     if (virStorageBackendUpdateVolInfo(vol, true,
                                        VIR_STORAGE_VOL_OPEN_DEFAULT, 0) < 0) {
-        goto cleanup;
+        return -1;
     }
 
     /* XXX should use logical unit's UUID instead */
     if (VIR_STRDUP(vol->key, vol->target.path) < 0)
-        goto cleanup;
+        return -1;
 
     if (virStoragePoolObjAddVol(pool, vol) < 0)
-        goto cleanup;
+        return -1;
 
     def->capacity += vol->target.capacity;
     def->allocation += vol->target.allocation;
-    ret = 0;
-
- cleanup:
+    vol = NULL;
 
-    if (ret != 0)
-        virStorageVolDefFree(vol);
-
-    return ret;
+    return 0;
 }
 
 
diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c
index cfbce1ad19..ece04f0f2d 100644
--- a/src/storage/storage_backend_rbd.c
+++ b/src/storage/storage_backend_rbd.c
@@ -618,7 +618,7 @@ virStorageBackendRBDRefreshPool(virStoragePoolObjPtr pool)
     }
 
     for (name = names; name < names + max_size;) {
-        virStorageVolDefPtr vol;
+        VIR_AUTOPTR(virStorageVolDef) vol = NULL;
 
         if (STREQ(name, ""))
             break;
@@ -626,10 +626,8 @@ virStorageBackendRBDRefreshPool(virStoragePoolObjPtr pool)
         if (VIR_ALLOC(vol) < 0)
             goto cleanup;
 
-        if (VIR_STRDUP(vol->name, name) < 0) {
-            VIR_FREE(vol);
+        if (VIR_STRDUP(vol->name, name) < 0)
             goto cleanup;
-        }
 
         name += strlen(name) + 1;
 
@@ -648,15 +646,14 @@ virStorageBackendRBDRefreshPool(virStoragePoolObjPtr pool)
             if (r == -ENOENT || r == -ETIMEDOUT)
                 continue;
 
-            virStorageVolDefFree(vol);
             goto cleanup;
         }
 
         if (virStoragePoolObjAddVol(pool, vol) < 0) {
-            virStorageVolDefFree(vol);
             virStoragePoolObjClearVols(pool);
             goto cleanup;
         }
+        vol = NULL;
     }
 
     VIR_DEBUG("Found %zu images in RBD pool %s",
diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_backend_sheepdog.c
index b6f424bea1..7cba6e02aa 100644
--- a/src/storage/storage_backend_sheepdog.c
+++ b/src/storage/storage_backend_sheepdog.c
@@ -110,30 +110,27 @@ virStorageBackendSheepdogAddHostArg(virCommandPtr cmd,
 static int
 virStorageBackendSheepdogAddVolume(virStoragePoolObjPtr pool, const char *diskInfo)
 {
-    virStorageVolDefPtr vol = NULL;
+    VIR_AUTOPTR(virStorageVolDef) vol = NULL;
 
     if (diskInfo == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Missing disk info when adding volume"));
-        goto error;
+        return -1;
     }
 
     if (VIR_ALLOC(vol) < 0 || VIR_STRDUP(vol->name, diskInfo) < 0)
-        goto error;
+        return -1;
 
     vol->type = VIR_STORAGE_VOL_NETWORK;
 
     if (virStorageBackendSheepdogRefreshVol(pool, vol) < 0)
-        goto error;
+        return -1;
 
     if (virStoragePoolObjAddVol(pool, vol) < 0)
-        goto error;
+        return -1;
+    vol = NULL;
 
     return 0;
-
- error:
-    virStorageVolDefFree(vol);
-    return -1;
 }
 
 static int
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 878a40cac5..48b4c5127f 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -1820,7 +1820,7 @@ storageVolCreateXML(virStoragePoolPtr pool,
     virStoragePoolObjPtr obj;
     virStoragePoolDefPtr def;
     virStorageBackendPtr backend;
-    virStorageVolDefPtr voldef = NULL;
+    VIR_AUTOPTR(virStorageVolDef) voldef = NULL;
     virStorageVolPtr vol = NULL, newvol = NULL;
 
     virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA, NULL);
@@ -1941,7 +1941,6 @@ storageVolCreateXML(virStoragePoolPtr pool,
 
  cleanup:
     virObjectUnref(newvol);
-    virStorageVolDefFree(voldef);
     virStoragePoolObjEndAPI(&obj);
     return vol;
 }
@@ -1957,7 +1956,7 @@ storageVolCreateXMLFrom(virStoragePoolPtr pool,
     virStoragePoolObjPtr objsrc = NULL;
     virStorageBackendPtr backend;
     virStorageVolDefPtr voldefsrc = NULL;
-    virStorageVolDefPtr voldef = NULL;
+    VIR_AUTOPTR(virStorageVolDef) voldef = NULL;
     virStorageVolDefPtr shadowvol = NULL;
     virStorageVolPtr newvol = NULL;
     virStorageVolPtr vol = NULL;
@@ -2134,7 +2133,6 @@ storageVolCreateXMLFrom(virStoragePoolPtr pool,
 
  cleanup:
     virObjectUnref(newvol);
-    virStorageVolDefFree(voldef);
     VIR_FREE(shadowvol);
     virStoragePoolObjEndAPI(&obj);
     virStoragePoolObjEndAPI(&objsrc);
diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index 95e05d950b..158cf3adb6 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -3672,7 +3672,7 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr pool)
     struct dirent *ent;
     struct statvfs sb;
     struct stat statbuf;
-    virStorageVolDefPtr vol = NULL;
+    VIR_AUTOPTR(virStorageVolDef) vol = NULL;
     virStorageSourcePtr target = NULL;
     int direrr;
     int fd = -1, ret = -1;
@@ -3767,7 +3767,6 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr pool)
  cleanup:
     VIR_DIR_CLOSE(dir);
     VIR_FORCE_CLOSE(fd);
-    virStorageVolDefFree(vol);
     virStorageSourceFree(target);
     if (ret < 0)
         virStoragePoolObjClearVols(pool);
@@ -3816,7 +3815,7 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
                             const char *dev)
 {
     virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
-    virStorageVolDefPtr vol = NULL;
+    VIR_AUTOPTR(virStorageVolDef) vol = NULL;
     char *devpath = NULL;
     int retval = -1;
 
@@ -3898,7 +3897,6 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
     retval = 0;
 
  cleanup:
-    virStorageVolDefFree(vol);
     VIR_FREE(devpath);
     return retval;
 }
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 743d03ae8b..44ae711b5a 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1025,7 +1025,7 @@ testOpenVolumesForPool(const char *file,
     size_t i;
     int num, ret = -1;
     xmlNodePtr *nodes = NULL;
-    virStorageVolDefPtr volDef = NULL;
+    VIR_AUTOPTR(virStorageVolDef) volDef = NULL;
 
     /* Find storage volumes */
     if (virAsprintf(&vol_xpath, "/node/pool[%d]/volume", objidx) < 0)
@@ -1064,7 +1064,6 @@ testOpenVolumesForPool(const char *file,
 
     ret = 0;
  error:
-    virStorageVolDefFree(volDef);
     VIR_FREE(nodes);
     return ret;
 }
@@ -5053,7 +5052,7 @@ testStorageVolCreateXML(virStoragePoolPtr pool,
     testDriverPtr privconn = pool->conn->privateData;
     virStoragePoolObjPtr obj;
     virStoragePoolDefPtr def;
-    virStorageVolDefPtr privvol = NULL;
+    VIR_AUTOPTR(virStorageVolDef) privvol = NULL;
     virStorageVolPtr ret = NULL;
 
     virCheckFlags(0, NULL);
@@ -5098,7 +5097,6 @@ testStorageVolCreateXML(virStoragePoolPtr pool,
     privvol = NULL;
 
  cleanup:
-    virStorageVolDefFree(privvol);
     virStoragePoolObjEndAPI(&obj);
     return ret;
 }
@@ -5113,7 +5111,8 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool,
     testDriverPtr privconn = pool->conn->privateData;
     virStoragePoolObjPtr obj;
     virStoragePoolDefPtr def;
-    virStorageVolDefPtr privvol = NULL, origvol = NULL;
+    VIR_AUTOPTR(virStorageVolDef) privvol = NULL;
+    virStorageVolDefPtr origvol = NULL;
     virStorageVolPtr ret = NULL;
 
     virCheckFlags(0, NULL);
@@ -5166,7 +5165,6 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool,
     privvol = NULL;
 
  cleanup:
-    virStorageVolDefFree(privvol);
     virStoragePoolObjEndAPI(&obj);
     return ret;
 }
diff --git a/src/vbox/vbox_storage.c b/src/vbox/vbox_storage.c
index 7047e54084..4ca342a449 100644
--- a/src/vbox/vbox_storage.c
+++ b/src/vbox/vbox_storage.c
@@ -401,7 +401,7 @@ vboxStorageVolCreateXML(virStoragePoolPtr pool,
                         const char *xml, unsigned int flags)
 {
     vboxDriverPtr data = pool->conn->privateData;
-    virStorageVolDefPtr def = NULL;
+    VIR_AUTOPTR(virStorageVolDef) def = NULL;
     PRUnichar *hddFormatUtf16 = NULL;
     PRUnichar *hddNameUtf16 = NULL;
     virStoragePoolDef poolDef;
@@ -501,7 +501,6 @@ vboxStorageVolCreateXML(virStoragePoolPtr pool,
     VBOX_RELEASE(progress);
     VBOX_UTF16_FREE(hddFormatUtf16);
     VBOX_UTF16_FREE(hddNameUtf16);
-    virStorageVolDefFree(def);
     return ret;
 }
 
diff --git a/tests/storagebackendsheepdogtest.c b/tests/storagebackendsheepdogtest.c
index 616af22d73..540f89c3ab 100644
--- a/tests/storagebackendsheepdogtest.c
+++ b/tests/storagebackendsheepdogtest.c
@@ -94,7 +94,7 @@ test_vdi_list_parser(const void *opaque)
     int ret = -1;
     char *output = NULL;
     virStoragePoolDefPtr pool = NULL;
-    virStorageVolDefPtr vol = NULL;
+    VIR_AUTOPTR(virStorageVolDef) vol = NULL;
 
     if (!(pool = virStoragePoolDefParseFile(data->poolxml)))
         goto cleanup;
@@ -121,7 +121,6 @@ test_vdi_list_parser(const void *opaque)
  cleanup:
     VIR_FREE(output);
     virStoragePoolDefFree(pool);
-    virStorageVolDefFree(vol);
     return ret;
 }
 
diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c
index bc2da37410..8e19f10b73 100644
--- a/tests/storagevolxml2argvtest.c
+++ b/tests/storagevolxml2argvtest.c
@@ -48,7 +48,8 @@ testCompareXMLToArgvFiles(bool shouldFail,
 
     virCommandPtr cmd = NULL;
 
-    virStorageVolDefPtr vol = NULL, inputvol = NULL;
+    VIR_AUTOPTR(virStorageVolDef) vol = NULL;
+    VIR_AUTOPTR(virStorageVolDef) inputvol = NULL;
     virStoragePoolDefPtr def = NULL;
     virStoragePoolDefPtr inputpool = NULL;
     virStoragePoolObjPtr obj = NULL;
@@ -139,8 +140,6 @@ testCompareXMLToArgvFiles(bool shouldFail,
 
  cleanup:
     virStoragePoolDefFree(inputpool);
-    virStorageVolDefFree(vol);
-    virStorageVolDefFree(inputvol);
     virCommandFree(cmd);
     VIR_FREE(actualCmdline);
     virStoragePoolObjEndAPI(&obj);
diff --git a/tests/storagevolxml2xmltest.c b/tests/storagevolxml2xmltest.c
index 040bbc7585..95e205a0ab 100644
--- a/tests/storagevolxml2xmltest.c
+++ b/tests/storagevolxml2xmltest.c
@@ -20,7 +20,7 @@ testCompareXMLToXMLFiles(const char *poolxml, const char *inxml,
     char *actual = NULL;
     int ret = -1;
     virStoragePoolDefPtr pool = NULL;
-    virStorageVolDefPtr dev = NULL;
+    VIR_AUTOPTR(virStorageVolDef) dev = NULL;
 
     if (!(pool = virStoragePoolDefParseFile(poolxml)))
         goto fail;
@@ -39,7 +39,6 @@ testCompareXMLToXMLFiles(const char *poolxml, const char *inxml,
  fail:
     VIR_FREE(actual);
     virStoragePoolDefFree(pool);
-    virStorageVolDefFree(dev);
     return ret;
 }
 
-- 
2.20.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux