From: Peter Krempa Date: Thu, 1 Oct 2020 09:45:55 +0000 (+0200) Subject: qemuMigrationCookieNetworkAlloc: Refactor memory handling X-Git-Tag: v6.9.0-rc1~338 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc032481812d907718dc4f09f5cd4db418771fd8;p=thirdparty%2Flibvirt.git qemuMigrationCookieNetworkAlloc: Refactor memory handling Use modern memory handling approach to simplify the code. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_cookie.c index e3b54f6ae9..87be9715af 100644 --- a/src/qemu/qemu_migration_cookie.c +++ b/src/qemu/qemu_migration_cookie.c @@ -220,16 +220,11 @@ static qemuMigrationCookieNetworkPtr qemuMigrationCookieNetworkAlloc(virQEMUDriverPtr driver G_GNUC_UNUSED, virDomainDefPtr def) { - qemuMigrationCookieNetworkPtr mig; + g_autoptr(qemuMigrationCookieNetwork) mig = g_new0(qemuMigrationCookieNetwork, 1); size_t i; - if (VIR_ALLOC(mig) < 0) - goto error; - mig->nnets = def->nnets; - - if (VIR_ALLOC_N(mig->net, def->nnets) <0) - goto error; + mig->net = g_new0(qemuMigrationCookieNetData, def->nnets); for (i = 0; i < def->nnets; i++) { virDomainNetDefPtr netptr; @@ -252,7 +247,7 @@ qemuMigrationCookieNetworkAlloc(virQEMUDriverPtr driver G_GNUC_UNUSED, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to run command to get OVS port data for " "interface %s"), netptr->ifname); - goto error; + return NULL; } break; default: @@ -260,11 +255,7 @@ qemuMigrationCookieNetworkAlloc(virQEMUDriverPtr driver G_GNUC_UNUSED, } } } - return mig; - - error: - qemuMigrationCookieNetworkFree(mig); - return NULL; + return g_steal_pointer(&mig); }