]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Free persistent def inside qemuMigrationCookieFree
authorJiri Denemark <jdenemar@redhat.com>
Tue, 21 Mar 2017 10:04:16 +0000 (11:04 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Mon, 27 Mar 2017 18:55:18 +0000 (20:55 +0200)
Creating a copy of the definition we want to add in a migration cookie
makes the code cleaner and less prone to memory leaks or double free
errors.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
src/qemu/qemu_migration.c
src/qemu/qemu_migration_cookie.c
src/qemu/qemu_migration_cookie.h

index 5913026026273cd2e4be9c783b1e9d42dc1acbd4..dabfe10c02e208d9b388e9a61bb4cb75bbd09c67 100644 (file)
@@ -3617,11 +3617,13 @@ qemuMigrationRun(virQEMUDriverPtr driver,
         if (persist_xml) {
             persistDef = qemuMigrationPrepareDef(driver, persist_xml,
                                                  NULL, NULL);
-            if (!persistDef)
-                goto cleanup;
         } else {
-            persistDef = vm->newDef;
+            persistDef = qemuDomainDefCopy(driver, vm->newDef,
+                                           VIR_DOMAIN_XML_SECURE |
+                                           VIR_DOMAIN_XML_MIGRATABLE);
         }
+        if (!persistDef)
+            goto cleanup;
     }
 
     mig = qemuMigrationEatCookie(driver, vm, cookiein, cookieinlen,
@@ -3868,14 +3870,13 @@ qemuMigrationRun(virQEMUDriverPtr driver,
                    QEMU_MIGRATION_COOKIE_STATS;
 
     if (ret == 0 &&
-        (qemuMigrationCookieAddPersistent(mig, persistDef) < 0 ||
+        (qemuMigrationCookieAddPersistent(mig, &persistDef) < 0 ||
          qemuMigrationBakeCookie(mig, driver, vm, cookieout,
                                  cookieoutlen, cookieFlags) < 0)) {
         VIR_WARN("Unable to encode migration cookie");
     }
 
-    if (persistDef != vm->newDef)
-        virDomainDefFree(persistDef);
+    virDomainDefFree(persistDef);
     qemuMigrationCookieFree(mig);
 
     if (events)
@@ -5365,10 +5366,7 @@ qemuMigrationFinish(virQEMUDriverPtr driver,
         qemuMonitorSetDomainLog(priv->mon, NULL, NULL, NULL);
     VIR_FREE(priv->origname);
     virDomainObjEndAPI(&vm);
-    if (mig) {
-        virDomainDefFree(qemuMigrationCookieGetPersistent(mig));
-        qemuMigrationCookieFree(mig);
-    }
+    qemuMigrationCookieFree(mig);
     if (orig_err) {
         virSetError(orig_err);
         virFreeError(orig_err);
index 0f4bcaddcc3b128b7107e6e57d6276128a17984b..bd12f11246a2a046fbad84ab07cfbd8d3ab2c965 100644 (file)
@@ -99,6 +99,7 @@ qemuMigrationCookieFree(qemuMigrationCookiePtr mig)
         return;
 
     qemuMigrationCookieGraphicsFree(mig->graphics);
+    virDomainDefFree(mig->persistent);
     qemuMigrationCookieNetworkFree(mig->network);
     qemuMigrationCookieNBDFree(mig->nbd);
 
@@ -385,7 +386,7 @@ qemuMigrationCookieAddLockstate(qemuMigrationCookiePtr mig,
 
 int
 qemuMigrationCookieAddPersistent(qemuMigrationCookiePtr mig,
-                                 virDomainDefPtr def)
+                                 virDomainDefPtr *def)
 {
     if (mig->flags & QEMU_MIGRATION_COOKIE_PERSISTENT) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -393,10 +394,11 @@ qemuMigrationCookieAddPersistent(qemuMigrationCookiePtr mig,
         return -1;
     }
 
-    if (!def)
+    if (!def || !*def)
         return 0;
 
-    mig->persistent = def;
+    mig->persistent = *def;
+    *def = NULL;
     mig->flags |= QEMU_MIGRATION_COOKIE_PERSISTENT;
     mig->flagsMandatory |= QEMU_MIGRATION_COOKIE_PERSISTENT;
     return 0;
index 0ef9d454a48e982e3e1dc7e3ecbadfbf042d7816..b009d5bf5dc06870926c5fe93d777009d631ca2e 100644 (file)
@@ -145,7 +145,7 @@ qemuMigrationCookieFree(qemuMigrationCookiePtr mig);
 
 int
 qemuMigrationCookieAddPersistent(qemuMigrationCookiePtr mig,
-                                 virDomainDefPtr def);
+                                 virDomainDefPtr *def);
 
 virDomainDefPtr
 qemuMigrationCookieGetPersistent(qemuMigrationCookiePtr mig);