From: Matt Coleman Date: Thu, 21 Jan 2021 18:51:33 +0000 (-0500) Subject: hyperv: use GLib auto-cleanup in hypervCreateInvokeXmlDoc X-Git-Tag: v7.1.0-rc1~448 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cc7a4b0139e65be02e4484ad58f59b390e41953f;p=thirdparty%2Flibvirt.git hyperv: use GLib auto-cleanup in hypervCreateInvokeXmlDoc Signed-off-by: Matt Coleman Reviewed-by: Laine Stump --- diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index 96ae9a40c8..a28bb0e815 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -398,38 +398,27 @@ hypervGetCimTypeInfo(hypervCimTypePtr typemap, const char *name, static int hypervCreateInvokeXmlDoc(hypervInvokeParamsListPtr params, WsXmlDocH *docRoot) { - int result = -1; - char *method = NULL; + g_autofree char *method = g_strdup_printf("%s_INPUT", params->method); + g_auto(WsXmlDocH) invokeXmlDocRoot = ws_xml_create_doc(NULL, method); WsXmlNodeH xmlNodeMethod = NULL; - method = g_strdup_printf("%s_INPUT", params->method); - - *docRoot = ws_xml_create_doc(NULL, method); - if (*docRoot == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Could not instantiate XML document")); - goto cleanup; + if (!invokeXmlDocRoot) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not instantiate XML document")); + return -1; } - xmlNodeMethod = xml_parser_get_root(*docRoot); - if (xmlNodeMethod == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Could not get root node of XML document")); - goto cleanup; + xmlNodeMethod = xml_parser_get_root(invokeXmlDocRoot); + if (!xmlNodeMethod) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not get root node of XML document")); + return -1; } /* add resource URI as namespace */ ws_xml_set_ns(xmlNodeMethod, params->resourceUri, "p"); - result = 0; + *docRoot = g_steal_pointer(&invokeXmlDocRoot); - cleanup: - if (result < 0 && *docRoot != NULL) { - ws_xml_destroy_doc(*docRoot); - *docRoot = NULL; - } - VIR_FREE(method); - return result; + return 0; }