From: Peter Krempa Date: Wed, 30 Sep 2020 12:58:26 +0000 (+0200) Subject: qemuMigrationCookieXMLParse: Switch to single-purpose temporary variables X-Git-Tag: v6.9.0-rc1~349 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4a7dd2780c306416d9e80c7bffbef26493ca6728;p=thirdparty%2Flibvirt.git qemuMigrationCookieXMLParse: Switch to single-purpose temporary variables Don't reuse 'tmp' over and over, but switch to single use automaticaly freed variables instead. 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 a6fdbc729a..5bd1746543 100644 --- a/src/qemu/qemu_migration_cookie.c +++ b/src/qemu/qemu_migration_cookie.c @@ -1207,8 +1207,10 @@ qemuMigrationCookieXMLParse(qemuMigrationCookiePtr mig, xmlXPathContextPtr ctxt, unsigned int flags) { - char uuidstr[VIR_UUID_STRING_BUFLEN]; - char *tmp = NULL; + g_autofree char *name = NULL; + g_autofree char *uuid = NULL; + g_autofree char *hostuuid = NULL; + char localdomuuid[VIR_UUID_STRING_BUFLEN]; xmlNodePtr *nodes = NULL; int n; @@ -1218,34 +1220,31 @@ qemuMigrationCookieXMLParse(qemuMigrationCookiePtr mig, */ /* Extract domain name */ - if (!(tmp = virXPathString("string(./name[1])", ctxt))) { + if (!(name = virXPathString("string(./name[1])", ctxt))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing name element in migration data")); goto error; } - if (STRNEQ(tmp, mig->name)) { + if (STRNEQ(name, mig->name)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Incoming cookie data had unexpected name %s vs %s"), - tmp, mig->name); + name, mig->name); goto error; } - VIR_FREE(tmp); /* Extract domain uuid */ - tmp = virXPathString("string(./uuid[1])", ctxt); - if (!tmp) { + if (!(uuid = virXPathString("string(./uuid[1])", ctxt))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing uuid element in migration data")); goto error; } - virUUIDFormat(mig->uuid, uuidstr); - if (STRNEQ(tmp, uuidstr)) { + virUUIDFormat(mig->uuid, localdomuuid); + if (STRNEQ(uuid, localdomuuid)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Incoming cookie data had unexpected UUID %s vs %s"), - tmp, uuidstr); + uuid, localdomuuid); goto error; } - VIR_FREE(tmp); if (!(mig->remoteHostname = virXPathString("string(./hostname[1])", ctxt))) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1258,12 +1257,12 @@ qemuMigrationCookieXMLParse(qemuMigrationCookiePtr mig, * for sure. */ /* Check & forbid localhost migration */ - if (!(tmp = virXPathString("string(./hostuuid[1])", ctxt))) { + if (!(hostuuid = virXPathString("string(./hostuuid[1])", ctxt))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing hostuuid element in migration data")); goto error; } - if (virUUIDParse(tmp, mig->remoteHostuuid) < 0) { + if (virUUIDParse(hostuuid, mig->remoteHostuuid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed hostuuid element in migration data")); goto error; @@ -1271,11 +1270,9 @@ qemuMigrationCookieXMLParse(qemuMigrationCookiePtr mig, if (memcmp(mig->remoteHostuuid, mig->localHostuuid, VIR_UUID_BUFLEN) == 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Attempt to migrate guest to the same host %s"), - tmp); + hostuuid); goto error; } - VIR_FREE(tmp); - if (qemuMigrationCookieXMLParseMandatoryFeatures(ctxt, flags) < 0) return -1; @@ -1350,7 +1347,6 @@ qemuMigrationCookieXMLParse(qemuMigrationCookiePtr mig, return 0; error: - VIR_FREE(tmp); VIR_FREE(nodes); return -1; }