]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virDomainDefValidateAliases: Refactor to avoid cleanup section
authorPeter Krempa <pkrempa@redhat.com>
Fri, 23 Jul 2021 08:43:12 +0000 (10:43 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 26 Jul 2021 11:27:30 +0000 (13:27 +0200)
Use a temporary auto-freed local variable to hold the hash table so that
the cleanup section can be removed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
src/conf/domain_validate.c

index aab377fbbd317c6ba8e2632475d2b7b75ced9315..a9e4519b1ab53d2176e0be240cad17e0339822ee 100644 (file)
@@ -1257,25 +1257,20 @@ static int
 virDomainDefValidateAliases(const virDomainDef *def,
                             GHashTable **aliases)
 {
-    struct virDomainDefValidateAliasesData data;
-    int ret = -1;
-
     /* We are not storing copies of aliases. Don't free them. */
-    data.aliases = virHashNew(NULL);
+    g_autoptr(GHashTable) tmpaliases = virHashNew(NULL);
+    struct virDomainDefValidateAliasesData data = { .aliases = tmpaliases };
 
     if (virDomainDeviceInfoIterateFlags((virDomainDef *) def,
                                         virDomainDeviceDefValidateAliasesIterator,
                                         DOMAIN_DEVICE_ITERATE_ALL_CONSOLES,
                                         &data) < 0)
-        goto cleanup;
+        return -1;
 
     if (aliases)
-        *aliases = g_steal_pointer(&data.aliases);
+        *aliases = g_steal_pointer(&tmpaliases);
 
-    ret = 0;
- cleanup:
-    virHashFree(data.aliases);
-    return ret;
+    return 0;
 }