Commit 9d513a4b3b for qemu.org
commit 9d513a4b3b420944ca6c0144e977d716c4020fb1
Author: niming <niming@sangfor.com.cn>
Date: Wed Nov 11 20:27:11 2026 +0800
migration: free migration blocker error in migrate_del_blocker() stub
The migrate_del_blocker() implementation in stubs/migr-blocker.c was an
empty no-op, while the real one in migration/migration.c takes ownership
of the Error from the migration blocker, frees it and then clears the
pointer:
void migrate_del_blocker(Error **reasonp)
{
if (*reasonp) {
...
error_free(*reasonp);
*reasonp = NULL;
}
}
Command line tools such as qemu-img link against the stub API. Block
drivers like vmdk allocate a migration blocker Error during open() (see
error_setg() in vmdk_open(), "does not support live migration") and pass
it to migrate_add_blocker_normal(). Because the stub migrate_add_blocker*()
is a no-op it does not take ownership of the Error, so on close the
stub migrate_del_blocker() has to free it itself; leaving the body empty
leaks the error message.
This becomes visible when running under ASan: "qemu-img info foo.vmdk"
leaks the migration-blocker error and hangs / fails to exit when the
image is closed.
Free the Error in the stub migrate_del_blocker() and set the pointer to
NULL to match the semantics of the real implementation. This also covers
every other driver that uses a migration blocker through the stub.
Signed-off-by: niming <niming@sangfor.com.cn>
Signed-off-by: zhuwei <zhuwei@sangfor.com.cn>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Signed-off-by: Fabiano Rosas <farosas@suse.de>
diff --git a/stubs/migr-blocker.c b/stubs/migr-blocker.c
index e54c7160d3..3c1f281381 100644
--- a/stubs/migr-blocker.c
+++ b/stubs/migr-blocker.c
@@ -1,5 +1,6 @@
#include "qemu/osdep.h"
#include "migration/blocker.h"
+#include "qapi/error.h"
int migrate_add_blocker(Error **reasonp, Error **errp)
{
@@ -18,4 +19,12 @@ int migrate_add_blocker_modes(Error **reasonp, unsigned modes, Error **errp)
void migrate_del_blocker(Error **reasonp)
{
+ /*
+ * migrate_add_blocker*() is a no-op here, so nobody owns the Error;
+ * free it to avoid a leak (e.g. "qemu-img info foo.vmdk").
+ */
+ if (reasonp && *reasonp) {
+ error_free(*reasonp);
+ *reasonp = NULL;
+ }
}