From: Peter Krempa Date: Fri, 2 Oct 2020 07:53:54 +0000 (+0200) Subject: qemuMigrationCookieNetworkXMLParse: Refactor memory handling X-Git-Tag: v6.9.0-rc1~336 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=abfb033ddb3aa78a1fcb89a904fdfc3d4dca555c;p=thirdparty%2Flibvirt.git qemuMigrationCookieNetworkXMLParse: Refactor memory handling Use modern allocators, automatic memory feeing, and decrease the scope of some variables to remove the 'error' label. 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 a4f602dcc5..d00aa2aa96 100644 --- a/src/qemu/qemu_migration_cookie.c +++ b/src/qemu/qemu_migration_cookie.c @@ -879,27 +879,24 @@ qemuMigrationCookieGraphicsXMLParse(xmlXPathContextPtr ctxt) static qemuMigrationCookieNetworkPtr qemuMigrationCookieNetworkXMLParse(xmlXPathContextPtr ctxt) { - qemuMigrationCookieNetworkPtr optr; + g_autoptr(qemuMigrationCookieNetwork) optr = g_new0(qemuMigrationCookieNetwork, 1); size_t i; int n; - xmlNodePtr *interfaces = NULL; - char *vporttype; + g_autofree xmlNodePtr *interfaces = NULL; VIR_XPATH_NODE_AUTORESTORE(ctxt) - if (VIR_ALLOC(optr) < 0) - goto error; - if ((n = virXPathNodeSet("./network/interface", ctxt, &interfaces)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing interface information")); - goto error; + return NULL; } optr->nnets = n; - if (VIR_ALLOC_N(optr->net, optr->nnets) < 0) - goto error; + optr->net = g_new0(qemuMigrationCookieNetData, optr->nnets); for (i = 0; i < n; i++) { + g_autofree char *vporttype = NULL; + /* portdata is optional, and may not exist */ ctxt->node = interfaces[i]; optr->net[i].portdata = virXPathString("string(./portdata[1])", ctxt); @@ -907,20 +904,12 @@ qemuMigrationCookieNetworkXMLParse(xmlXPathContextPtr ctxt) if (!(vporttype = virXMLPropString(interfaces[i], "vporttype"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing vporttype attribute in migration data")); - goto error; + return NULL; } optr->net[i].vporttype = virNetDevVPortTypeFromString(vporttype); - VIR_FREE(vporttype); } - VIR_FREE(interfaces); - - return optr; - - error: - VIR_FREE(interfaces); - qemuMigrationCookieNetworkFree(optr); - return NULL; + return g_steal_pointer(&optr); }