]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuMigrationCookieNew: Refactor allocation and cleanup
authorPeter Krempa <pkrempa@redhat.com>
Mon, 28 Sep 2020 15:03:33 +0000 (17:03 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 1 Oct 2020 08:01:05 +0000 (10:01 +0200)
Move around some code so that we can get rid of the 'cleanup:' label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_migration_cookie.c

index 124f61e3ea8f2611c7787f4cf948366d03a46b8c..a04b74f092e4ef5e721a94d2a2b087fa67f3e87a 100644 (file)
@@ -280,31 +280,30 @@ qemuMigrationCookieNew(const virDomainDef *def,
                        const char *origname)
 {
     qemuMigrationCookiePtr mig = NULL;
-    const char *name;
+    unsigned char localHostUUID[VIR_UUID_BUFLEN];
+    g_autofree char *localHostname = NULL;
 
-    if (VIR_ALLOC(mig) < 0)
-        goto error;
-
-    if (origname)
-        name = origname;
-    else
-        name = def->name;
-    mig->name = g_strdup(name);
-    memcpy(mig->uuid, def->uuid, VIR_UUID_BUFLEN);
+    if (!(localHostname = virGetHostname()))
+        return NULL;
 
-    if (!(mig->localHostname = virGetHostname()))
-        goto error;
-    if (virGetHostUUID(mig->localHostuuid) < 0) {
+    if (virGetHostUUID(localHostUUID) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Unable to obtain host UUID"));
-        goto error;
+        return NULL;
     }
 
-    return mig;
+    mig = g_new0(qemuMigrationCookie, 1);
 
- error:
-    qemuMigrationCookieFree(mig);
-    return NULL;
+    if (origname)
+        mig->name = g_strdup(origname);
+    else
+        mig->name = g_strdup(def->name);
+
+    memcpy(mig->uuid, def->uuid, VIR_UUID_BUFLEN);
+    memcpy(mig->localHostuuid, localHostUUID, VIR_UUID_BUFLEN);
+    mig->localHostname = g_steal_pointer(&localHostname);
+
+    return mig;
 }