[PATCH 02/20] qemuMigrationCookieXMLParse: Switch to single-purpose temporary variables

Peter Krempa pkrempa at redhat.com
Fri Oct 2 08:57:36 UTC 2020


Don't reuse 'tmp' over and over, but switch to single use automaticaly
freed variables instead.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/qemu/qemu_migration_cookie.c | 32 ++++++++++++++------------------
 1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_cookie.c
index 22705874e0..f313b6d00e 100644
--- a/src/qemu/qemu_migration_cookie.c
+++ b/src/qemu/qemu_migration_cookie.c
@@ -1210,8 +1210,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;

@@ -1221,34 +1223,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,
@@ -1261,12 +1260,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;
@@ -1274,11 +1273,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;
@@ -1353,7 +1350,6 @@ qemuMigrationCookieXMLParse(qemuMigrationCookiePtr mig,
     return 0;

  error:
-    VIR_FREE(tmp);
     VIR_FREE(nodes);
     return -1;
 }
-- 
2.26.2




More information about the libvir-list mailing list