From 0436a144681ae4e0790932e31347d3471823c12e Mon Sep 17 00:00:00 2001 From: Daniel Henrique Barboza Date: Tue, 24 Nov 2020 11:22:00 -0300 Subject: [PATCH] domain_conf.c: modernize virDomainDefControllersParse() The 'error' label is just returning -1, so let's 'return -1' directly. Use g_autoptr() with virDomainControllerDefPtr to remove the need to call virDomainControllerDefFree() in the error path. There is no need to VIR_FREE(nodes) explictly since 'nodes' is using g_autofree. Reviewed-by: Michal Privoznik Signed-off-by: Daniel Henrique Barboza --- src/conf/domain_conf.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c789261087..49b68c2c68 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -21731,38 +21731,36 @@ virDomainDefControllersParse(virDomainDefPtr def, int n; if ((n = virXPathNodeSet("./devices/controller", ctxt, &nodes)) < 0) - goto error; + return -1; if (n) def->controllers = g_new0(virDomainControllerDefPtr, n); for (i = 0; i < n; i++) { - virDomainControllerDefPtr controller = virDomainControllerDefParseXML(xmlopt, - nodes[i], - ctxt, - flags); + g_autoptr(virDomainControllerDef) controller = NULL; + + controller = virDomainControllerDefParseXML(xmlopt, nodes[i], + ctxt, flags); if (!controller) - goto error; + return -1; /* sanitize handling of "none" usb controller */ if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_USB) { if (controller->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE) { if (usb_other || *usb_none) { - virDomainControllerDefFree(controller); virReportError(VIR_ERR_XML_DETAIL, "%s", _("Can't add another USB controller: " "USB is disabled for this domain")); - goto error; + return -1; } *usb_none = true; } else { if (*usb_none) { - virDomainControllerDefFree(controller); virReportError(VIR_ERR_XML_DETAIL, "%s", _("Can't add another USB controller: " "USB is disabled for this domain")); - goto error; + return -1; } usb_other = true; } @@ -21771,20 +21769,16 @@ virDomainDefControllersParse(virDomainDefPtr def, usb_master = true; } - virDomainControllerInsertPreAlloced(def, controller); + virDomainControllerInsertPreAlloced(def, g_steal_pointer(&controller)); } - VIR_FREE(nodes); if (usb_other && !usb_master) { virReportError(VIR_ERR_XML_DETAIL, "%s", _("No master USB controller specified")); - goto error; + return -1; } return 0; - - error: - return -1; } static virDomainDefPtr