[libvirt] [PATCH v2 1/3] virTestCompareToULL: Use VIR_AUTOFREE()

Michal Privoznik mprivozn at redhat.com
Wed Feb 20 13:20:08 UTC 2019


In order to save a few lines of code, and also since it's hype
let's use VIR_AUTOFREE() for the two strings we allocate there.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 tests/testutils.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)

diff --git a/tests/testutils.c b/tests/testutils.c
index d2219ad21e..ac86418653 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -822,23 +822,16 @@ int
 virTestCompareToULL(unsigned long long content,
                     unsigned long long src)
 {
-    char *strcontent = NULL;
-    char *strsrc = NULL;
-    int ret = -1;
+    VIR_AUTOFREE(char *) strcontent = NULL;
+    VIR_AUTOFREE(char *) strsrc = NULL;
 
     if (virAsprintf(&strcontent, "%llu", content) < 0)
-        goto cleanup;
+        return -1;
 
     if (virAsprintf(&strsrc, "%llu", src) < 0)
-        goto cleanup;
+        return -1;
 
-    ret = virTestCompareToString(strcontent, strsrc);
-
- cleanup:
-    VIR_FREE(strcontent);
-    VIR_FREE(strsrc);
-
-    return ret;
+    return virTestCompareToString(strcontent, strsrc);
 }
 
 /*
-- 
2.19.2




More information about the libvir-list mailing list