[libvirt PATCH] cpu_map: Use g_auto* in cpuMapLoad

Tim Wiederhake posted 1 patch 3 years, 6 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20200904122607.46753-1-twiederh@redhat.com
src/cpu/cpu_map.c | 33 ++++++++++++---------------------
1 file changed, 12 insertions(+), 21 deletions(-)
[libvirt PATCH] cpu_map: Use g_auto* in cpuMapLoad
Posted by Tim Wiederhake 3 years, 6 months ago
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
---
 src/cpu/cpu_map.c | 33 ++++++++++++---------------------
 1 file changed, 12 insertions(+), 21 deletions(-)

diff --git a/src/cpu/cpu_map.c b/src/cpu/cpu_map.c
index 913e34a067..cbf90d1395 100644
--- a/src/cpu/cpu_map.c
+++ b/src/cpu/cpu_map.c
@@ -169,12 +169,11 @@ int cpuMapLoad(const char *arch,
                cpuMapLoadCallback modelCB,
                void *data)
 {
-    xmlDocPtr xml = NULL;
-    xmlXPathContextPtr ctxt = NULL;
+    g_autoptr(xmlDoc) xml = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
-    char *xpath = NULL;
-    int ret = -1;
-    char *mapfile;
+    g_autofree char *xpath = NULL;
+    g_autofree char *mapfile = NULL;
 
     if (!(mapfile = virFileFindResource("index.xml",
                                         abs_top_srcdir "/src/cpu_map",
@@ -186,11 +185,11 @@ int cpuMapLoad(const char *arch,
     if (arch == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "%s", _("undefined hardware architecture"));
-        goto cleanup;
+        return -1;
     }
 
     if (!(xml = virXMLParseFileCtxt(mapfile, &ctxt)))
-        goto cleanup;
+        return -1;
 
     virBufferAsprintf(&buf, "./arch[@name='%s']", arch);
 
@@ -201,28 +200,20 @@ int cpuMapLoad(const char *arch,
     if ((ctxt->node = virXPathNode(xpath, ctxt)) == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("cannot find CPU map for %s architecture"), arch);
-        goto cleanup;
+        return -1;
     }
 
     if (loadData(mapfile, ctxt, "vendor", vendorCB, data) < 0)
-        goto cleanup;
+        return -1;
 
     if (loadData(mapfile, ctxt, "feature", featureCB, data) < 0)
-        goto cleanup;
+        return -1;
 
     if (loadData(mapfile, ctxt, "model", modelCB, data) < 0)
-        goto cleanup;
+        return -1;
 
     if (loadIncludes(ctxt, vendorCB, featureCB, modelCB, data) < 0)
-        goto cleanup;
-
-    ret = 0;
-
- cleanup:
-    xmlXPathFreeContext(ctxt);
-    xmlFreeDoc(xml);
-    VIR_FREE(xpath);
-    VIR_FREE(mapfile);
+        return -1;
 
-    return ret;
+    return 0;
 }
-- 
2.26.2

Re: [libvirt PATCH] cpu_map: Use g_auto* in cpuMapLoad
Posted by Ján Tomko 3 years, 6 months ago
On a Friday in 2020, Tim Wiederhake wrote:
>Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
>---
> src/cpu/cpu_map.c | 33 ++++++++++++---------------------
> 1 file changed, 12 insertions(+), 21 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>
and pushed.

Jano