]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemuDomainCleanupRun: Actually run cleanup callbacks in reverse order
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 5 May 2020 11:45:44 +0000 (13:45 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 11 May 2020 11:20:19 +0000 (13:20 +0200)
We have a framework to register cleanup callbacks that are run
when a domain is shut down. The idea is to run callbacks in
reverse order than they were registered. However, looking at the
code this is not the case. Fortunately, this framework is used to
register a single callback and a single callback only -
qemuMigrationDstPrepareCleanup() - therefore there was no problem
just yet.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_domain.c

index 9c629c31a383bfca781fc2e208e7337ddc36877e..7c71b797bc9e9ff5a467578c29a84536376a6b7d 100644 (file)
@@ -8032,18 +8032,14 @@ qemuDomainCleanupRun(virQEMUDriverPtr driver,
                      virDomainObjPtr vm)
 {
     qemuDomainObjPrivatePtr priv = vm->privateData;
-    size_t i;
 
     VIR_DEBUG("driver=%p, vm=%s", driver, vm->def->name);
 
     /* run cleanup callbacks in reverse order */
-    for (i = 0; i < priv->ncleanupCallbacks; i++) {
-        if (priv->cleanupCallbacks[priv->ncleanupCallbacks - (i + 1)])
-            priv->cleanupCallbacks[i](driver, vm);
-    }
+    while (priv->ncleanupCallbacks)
+        priv->cleanupCallbacks[--priv->ncleanupCallbacks](driver, vm);
 
     VIR_FREE(priv->cleanupCallbacks);
-    priv->ncleanupCallbacks = 0;
     priv->ncleanupCallbacks_max = 0;
 }