]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuMigrationCookieXMLFormat: Refactor memory handling
authorPeter Krempa <pkrempa@redhat.com>
Fri, 2 Oct 2020 07:50:37 +0000 (09:50 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 5 Oct 2020 13:58:53 +0000 (15:58 +0200)
Use automatic memory freeing to get rid of the 'error' label. Since the
'tmp' variable was used only in one instance, rename it appropriately.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_migration_cookie.c

index 87be9715af651d8ff8ec664a82906716ee662310..a4f602dcc5b0d3e373022923c7278fa44839c790 100644 (file)
@@ -839,49 +839,40 @@ qemuMigrationCookieXMLFormat(virQEMUDriverPtr driver,
 static qemuMigrationCookieGraphicsPtr
 qemuMigrationCookieGraphicsXMLParse(xmlXPathContextPtr ctxt)
 {
-    qemuMigrationCookieGraphicsPtr grap;
-    char *tmp;
+    g_autoptr(qemuMigrationCookieGraphics) grap = g_new0(qemuMigrationCookieGraphics, 1);
+    g_autofree char *graphicstype = NULL;
 
-    if (VIR_ALLOC(grap) < 0)
-        goto error;
-
-    if (!(tmp = virXPathString("string(./graphics/@type)", ctxt))) {
+    if (!(graphicstype = virXPathString("string(./graphics/@type)", ctxt))) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "%s", _("missing type attribute in migration data"));
-        goto error;
+        return NULL;
     }
-    if ((grap->type = virDomainGraphicsTypeFromString(tmp)) < 0) {
+    if ((grap->type = virDomainGraphicsTypeFromString(graphicstype)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("unknown graphics type %s"), tmp);
-        VIR_FREE(tmp);
-        goto error;
+                       _("unknown graphics type %s"), graphicstype);
+        return NULL;
     }
-    VIR_FREE(tmp);
     if (virXPathInt("string(./graphics/@port)", ctxt, &grap->port) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "%s", _("missing port attribute in migration data"));
-        goto error;
+        return NULL;
     }
     if (grap->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
         if (virXPathInt("string(./graphics/@tlsPort)", ctxt, &grap->tlsPort) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            "%s", _("missing tlsPort attribute in migration data"));
-            goto error;
+            return NULL;
         }
     }
     if (!(grap->listen = virXPathString("string(./graphics/@listen)", ctxt))) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "%s", _("missing listen attribute in migration data"));
-        goto error;
+        return NULL;
     }
     /* Optional */
     grap->tlsSubject = virXPathString("string(./graphics/cert[@info='subject']/@value)", ctxt);
 
-    return grap;
-
- error:
-    qemuMigrationCookieGraphicsFree(grap);
-    return NULL;
+    return g_steal_pointer(&grap);
 }