migration: Plug memory leak with migration URIs

migrate_uri_parse() allocates memory to 'channel' if the user
opts for old syntax - uri, which is leaked because there is no
code for freeing 'channel'.
So, free channel to avoid memory leak in case where 'channels'
is empty and uri parsing is required.

Fixes: 5994024f ("migration: Implement MigrateChannelList to qmp migration flow")
Signed-off-by: Het Gala <het.gala@nutanix.com>
Suggested-by: Markus Armbruster <armbru@redhat.com>
Tested-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Link: https://lore.kernel.org/r/20231129204301.131228-1-het.gala@nutanix.com
Signed-off-by: Peter Xu <peterx@redhat.com>
This commit is contained in:
Het Gala 2023-11-29 20:43:01 +00:00 committed by Peter Xu
parent abf635ddfe
commit bc1d54ee51

View File

@ -515,7 +515,7 @@ static void qemu_start_incoming_migration(const char *uri, bool has_channels,
MigrationChannelList *channels, MigrationChannelList *channels,
Error **errp) Error **errp)
{ {
MigrationChannel *channel = NULL; g_autoptr(MigrationChannel) channel = NULL;
MigrationAddress *addr = NULL; MigrationAddress *addr = NULL;
MigrationIncomingState *mis = migration_incoming_get_current(); MigrationIncomingState *mis = migration_incoming_get_current();
@ -533,18 +533,18 @@ static void qemu_start_incoming_migration(const char *uri, bool has_channels,
error_setg(errp, "Channel list has more than one entries"); error_setg(errp, "Channel list has more than one entries");
return; return;
} }
channel = channels->value; addr = channels->value->addr;
} else if (uri) { } else if (uri) {
/* caller uses the old URI syntax */ /* caller uses the old URI syntax */
if (!migrate_uri_parse(uri, &channel, errp)) { if (!migrate_uri_parse(uri, &channel, errp)) {
return; return;
} }
addr = channel->addr;
} else { } else {
error_setg(errp, "neither 'uri' or 'channels' argument are " error_setg(errp, "neither 'uri' or 'channels' argument are "
"specified in 'migrate-incoming' qmp command "); "specified in 'migrate-incoming' qmp command ");
return; return;
} }
addr = channel->addr;
/* transport mechanism not suitable for migration? */ /* transport mechanism not suitable for migration? */
if (!migration_channels_and_transport_compatible(addr, errp)) { if (!migration_channels_and_transport_compatible(addr, errp)) {
@ -1932,7 +1932,7 @@ void qmp_migrate(const char *uri, bool has_channels,
bool resume_requested; bool resume_requested;
Error *local_err = NULL; Error *local_err = NULL;
MigrationState *s = migrate_get_current(); MigrationState *s = migrate_get_current();
MigrationChannel *channel = NULL; g_autoptr(MigrationChannel) channel = NULL;
MigrationAddress *addr = NULL; MigrationAddress *addr = NULL;
/* /*
@ -1949,18 +1949,18 @@ void qmp_migrate(const char *uri, bool has_channels,
error_setg(errp, "Channel list has more than one entries"); error_setg(errp, "Channel list has more than one entries");
return; return;
} }
channel = channels->value; addr = channels->value->addr;
} else if (uri) { } else if (uri) {
/* caller uses the old URI syntax */ /* caller uses the old URI syntax */
if (!migrate_uri_parse(uri, &channel, errp)) { if (!migrate_uri_parse(uri, &channel, errp)) {
return; return;
} }
addr = channel->addr;
} else { } else {
error_setg(errp, "neither 'uri' or 'channels' argument are " error_setg(errp, "neither 'uri' or 'channels' argument are "
"specified in 'migrate' qmp command "); "specified in 'migrate' qmp command ");
return; return;
} }
addr = channel->addr;
/* transport mechanism not suitable for migration? */ /* transport mechanism not suitable for migration? */
if (!migration_channels_and_transport_compatible(addr, errp)) { if (!migration_channels_and_transport_compatible(addr, errp)) {