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(a)redhat.com>
---
src/qemu/qemu_migration_cookie.c | 31 +++++++++++--------------------
1 file changed, 11 insertions(+), 20 deletions(-)
diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_cookie.c
index 7a1d115ae5..8b5491e388 100644
--- a/src/qemu/qemu_migration_cookie.c
+++ b/src/qemu/qemu_migration_cookie.c
@@ -842,49 +842,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);
}
--
2.26.2