]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: Introduce VIR_DEFINE_AUTOPTR_FUNC for virStorageAuthDef
authorJohn Ferlan <jferlan@redhat.com>
Thu, 31 Jan 2019 12:48:42 +0000 (07:48 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 12 Feb 2019 13:51:23 +0000 (08:51 -0500)
Let's make use of the auto __cleanup capabilities cleaning up any
now unnecessary goto paths.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/domain_conf.c
src/conf/storage_conf.c
src/qemu/qemu_parse_command.c
src/util/virstoragefile.c
src/util/virstoragefile.h

index a33f18c9570378abe9583165e336be0721cd2422..2b1389035e2f7ec1948b2ca763fac97ee0f929cd 100644 (file)
@@ -7578,11 +7578,10 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode,
                                            virDomainHostdevSubsysSCSIPtr def,
                                            xmlXPathContextPtr ctxt)
 {
-    int ret = -1;
     int auth_secret_usage = -1;
     xmlNodePtr cur;
-    virStorageAuthDefPtr authdef = NULL;
     virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc = &def->u.iscsi;
+    VIR_AUTOPTR(virStorageAuthDef) authdef = NULL;
 
     /* For the purposes of command line creation, this needs to look
      * like a disk storage source */
@@ -7594,23 +7593,23 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode,
     if (!(iscsisrc->src->path = virXMLPropString(sourcenode, "name"))) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("missing iSCSI hostdev source path name"));
-        goto cleanup;
+        return -1;
     }
 
     if (virDomainStorageNetworkParseHosts(sourcenode, &iscsisrc->src->hosts,
                                           &iscsisrc->src->nhosts) < 0)
-        goto cleanup;
+        return -1;
 
     if (iscsisrc->src->nhosts < 1) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("missing the host address for the iSCSI hostdev"));
-        goto cleanup;
+        return -1;
     }
     if (iscsisrc->src->nhosts > 1) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("only one source host address may be specified "
                          "for the iSCSI hostdev"));
-        goto cleanup;
+        return -1;
     }
 
     cur = sourcenode->children;
@@ -7618,29 +7617,25 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode,
         if (cur->type == XML_ELEMENT_NODE &&
             virXMLNodeNameEqual(cur, "auth")) {
             if (!(authdef = virStorageAuthDefParse(cur, ctxt)))
-                goto cleanup;
+                return -1;
             if ((auth_secret_usage =
                  virSecretUsageTypeFromString(authdef->secrettype)) < 0) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                                _("invalid secret type %s"),
                                authdef->secrettype);
-                goto cleanup;
+                return -1;
             }
             if (auth_secret_usage != VIR_SECRET_USAGE_TYPE_ISCSI) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("hostdev invalid secret type '%s'"),
                                authdef->secrettype);
-                goto cleanup;
+                return -1;
             }
             VIR_STEAL_PTR(iscsisrc->src->auth, authdef);
         }
         cur = cur->next;
     }
-    ret = 0;
-
- cleanup:
-    virStorageAuthDefFree(authdef);
-    return ret;
+    return 0;
 }
 
 static int
@@ -9683,7 +9678,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
     virStorageEncryptionPtr encryption = NULL;
     char *serial = NULL;
     char *startupPolicy = NULL;
-    virStorageAuthDefPtr authdef = NULL;
     char *tray = NULL;
     char *removable = NULL;
     char *logical_block_size = NULL;
@@ -9692,6 +9686,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
     char *vendor = NULL;
     char *product = NULL;
     char *domain_name = NULL;
+    VIR_AUTOPTR(virStorageAuthDef) authdef = NULL;
 
     if (!(def = virDomainDiskDefNew(xmlopt)))
         return NULL;
@@ -10093,7 +10088,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
     VIR_FREE(target);
     VIR_FREE(tray);
     VIR_FREE(removable);
-    virStorageAuthDefFree(authdef);
     VIR_FREE(devaddr);
     VIR_FREE(serial);
     virStorageEncryptionFree(encryption);
index fbd62e1305d33766ceb607a1b9db5256dd5b9232..ead24816bcf04ef423e2b5f03158c3c1bbcd0da4 100644 (file)
@@ -458,11 +458,11 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
     int nsource;
     size_t i;
     virStoragePoolOptionsPtr options;
-    virStorageAuthDefPtr authdef = NULL;
     char *name = NULL;
     char *port = NULL;
     char *ver = NULL;
     int n;
+    VIR_AUTOPTR(virStorageAuthDef) authdef = NULL;
 
     relnode = ctxt->node;
     ctxt->node = node;
@@ -614,7 +614,6 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
 
     VIR_FREE(port);
     VIR_FREE(nodeset);
-    virStorageAuthDefFree(authdef);
     return ret;
 }
 
index 679d49d442008d220a6640c780bd8ef095773a3d..81691cb85ee17b7e6d7406177e4eea559633ca4b 100644 (file)
@@ -59,7 +59,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri,
     char *sock = NULL;
     char *volimg = NULL;
     char *secret = NULL;
-    virStorageAuthDefPtr authdef = NULL;
+    VIR_AUTOPTR(virStorageAuthDef) authdef = NULL;
 
     if (VIR_ALLOC(def->src->hosts) < 0)
         goto error;
@@ -151,7 +151,6 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri,
  error:
     virStorageNetHostDefClear(def->src->hosts);
     VIR_FREE(def->src->hosts);
-    virStorageAuthDefFree(authdef);
     goto cleanup;
 }
 
index 7fbeea78eb0c2adee1bc53ea1201cfc018e4ea09..1eb1ede59d1833ac3fd07dc282f02aa17652bce0 100644 (file)
@@ -1879,25 +1879,23 @@ virStorageAuthDefFree(virStorageAuthDefPtr authdef)
 virStorageAuthDefPtr
 virStorageAuthDefCopy(const virStorageAuthDef *src)
 {
-    virStorageAuthDefPtr authdef;
     virStorageAuthDefPtr ret = NULL;
+    VIR_AUTOPTR(virStorageAuthDef) authdef = NULL;
 
     if (VIR_ALLOC(authdef) < 0)
         return NULL;
 
     if (VIR_STRDUP(authdef->username, src->username) < 0)
-        goto cleanup;
+        return NULL;
     /* Not present for storage pool, but used for disk source */
     if (VIR_STRDUP(authdef->secrettype, src->secrettype) < 0)
-        goto cleanup;
+        return NULL;
     authdef->authType = src->authType;
 
     if (virSecretLookupDefCopy(&authdef->seclookupdef, &src->seclookupdef) < 0)
-        goto cleanup;
+        return NULL;
 
     VIR_STEAL_PTR(ret, authdef);
- cleanup:
-    virStorageAuthDefFree(authdef);
     return ret;
 }
 
@@ -1907,10 +1905,10 @@ virStorageAuthDefParse(xmlNodePtr node,
                        xmlXPathContextPtr ctxt)
 {
     xmlNodePtr saveNode = ctxt->node;
-    virStorageAuthDefPtr authdef = NULL;
     virStorageAuthDefPtr ret = NULL;
     xmlNodePtr secretnode = NULL;
     char *authtype = NULL;
+    VIR_AUTOPTR(virStorageAuthDef) authdef = NULL;
 
     ctxt->node = node;
 
@@ -1958,7 +1956,6 @@ virStorageAuthDefParse(xmlNodePtr node,
 
  cleanup:
     VIR_FREE(authtype);
-    virStorageAuthDefFree(authdef);
     ctxt->node = saveNode;
 
     return ret;
@@ -2832,7 +2829,7 @@ virStorageSourceParseRBDColonString(const char *rbdstr,
 {
     char *options = NULL;
     char *p, *e, *next;
-    virStorageAuthDefPtr authdef = NULL;
+    VIR_AUTOPTR(virStorageAuthDef) authdef = NULL;
 
     /* optionally skip the "rbd:" prefix if provided */
     if (STRPREFIX(rbdstr, "rbd:"))
@@ -2935,7 +2932,6 @@ virStorageSourceParseRBDColonString(const char *rbdstr,
 
  error:
     VIR_FREE(options);
-    virStorageAuthDefFree(authdef);
     return -1;
 }
 
index a98d5103fa4f84531df3a334fc6e72803cbc7ed6..eacc927ea63def9efacf8e572638eb135888d806 100644 (file)
@@ -543,4 +543,6 @@ void virStorageFileReportBrokenChain(int errcode,
                                      virStorageSourcePtr src,
                                      virStorageSourcePtr parent);
 
+VIR_DEFINE_AUTOPTR_FUNC(virStorageAuthDef, virStorageAuthDefFree);
+
 #endif /* LIBVIRT_VIRSTORAGEFILE_H */