]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
hyperv: use GLib auto-cleanup in hypervCreateInvokeXmlDoc
authorMatt Coleman <mcoleman@datto.com>
Thu, 21 Jan 2021 18:51:33 +0000 (13:51 -0500)
committerLaine Stump <laine@redhat.com>
Fri, 22 Jan 2021 19:04:29 +0000 (14:04 -0500)
Signed-off-by: Matt Coleman <matt@datto.com>
Reviewed-by: Laine Stump <laine@redhat.com>
src/hyperv/hyperv_wmi.c

index 96ae9a40c8a2430e7adad8b9ed267d39a79e1c2e..a28bb0e815ecd38409f32bf62aa082cf9eaa90ef 100644 (file)
@@ -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;
 }