During migration there are usually two references to the iochannel,
one from the channel creation itself and another from the ownership
transfer into QEMUFile.
- The reference from the QEMUFile is decremented at qemu_fclose.
- The original reference is decremented at migration_connect_outgoing()
for regular migration and not at all for snapshots.
The ide-test has recently added migration support and ASAN has
flagged:
Indirect leak of 32 byte(s) in 1 object(s) allocated from:
#0 0x55ca12aac0b9 in realloc
#1 0x7fd97d7e5a05 in g_realloc
#3 0x7fd97d7c98c6 in g_hash_table_new_full
#4 0x55ca14e186f1 in object_initialize_with_type ../qom/object.c:506:23
#5 0x55ca14e1a590 in object_new_with_type ../qom/object.c:706:5
#6 0x55ca14e1a7e8 in object_new ../qom/object.c:722:12
#7 0x55ca12de896f in qio_channel_block_new
../migration/channel-block.c:32:29
#8 0x55ca12ec8f2d in qemu_fopen_bdrv ../migration/savevm.c:172:49
#9 0x55ca12ec8b42 in save_snapshot ../migration/savevm.c:3375:9
#10 0x55ca12ee18e3 in hmp_savevm ../migration/migration-hmp-cmds.c:497:5
Change qemu_fopen_bdrv() to drop the original reference once the
QEMUFile has taken over the object. The xen code already does the
same.
Reviewed-by: Marc-André Lureau <[email protected]>
Reviewed-by: Peter Xu <[email protected]>
Signed-off-by: Fabiano Rosas <[email protected]>
---
migration/savevm.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/migration/savevm.c b/migration/savevm.c
index 5b0e89ca7c..8d4bdc28ab 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -168,11 +168,16 @@ static bool qemu_loadvm_thread_pool_wait(MigrationState
*s,
static QEMUFile *qemu_fopen_bdrv(BlockDriverState *bs, int is_writable)
{
+ QIOChannel *ioc = QIO_CHANNEL(qio_channel_block_new(bs));
+ QEMUFile *f;
+
if (is_writable) {
- return qemu_file_new_output(QIO_CHANNEL(qio_channel_block_new(bs)));
+ f = qemu_file_new_output(ioc);
} else {
- return qemu_file_new_input(QIO_CHANNEL(qio_channel_block_new(bs)));
+ f = qemu_file_new_input(ioc);
}
+ object_unref(ioc);
+ return f;
}
--
2.53.0