[libvirt PATCH 2/6] tests: esxutils: reduce variable scope in testEscapeDatastoreItem

Ján Tomko jtomko at redhat.com
Sat Sep 4 19:34:48 UTC 2021


Also use g_auto.

Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 tests/esxutilstest.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/tests/esxutilstest.c b/tests/esxutilstest.c
index bfb35fa356..d537da3011 100644
--- a/tests/esxutilstest.c
+++ b/tests/esxutilstest.c
@@ -161,23 +161,19 @@ static int
 testEscapeDatastoreItem(const void *data G_GNUC_UNUSED)
 {
     size_t i;
-    char *escaped = NULL;
 
     for (i = 0; i < G_N_ELEMENTS(datastoreItems); ++i) {
-        VIR_FREE(escaped);
+        g_autofree char *escaped = NULL;
 
         escaped = esxUtil_EscapeDatastoreItem(datastoreItems[i].string);
 
         if (escaped == NULL)
             return -1;
 
-        if (STRNEQ(datastoreItems[i].escaped, escaped)) {
-            VIR_FREE(escaped);
+        if (STRNEQ(datastoreItems[i].escaped, escaped))
             return -1;
-        }
     }
 
-    VIR_FREE(escaped);
     return 0;
 }
 
-- 
2.31.1




More information about the libvir-list mailing list