[libvirt PATCH 07/24] tests: libxl: use g_autofree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 tests/libxlxml2domconfigtest.c | 15 +++++----------
 tests/xlconfigtest.c           | 25 ++++++++-----------------
 tests/xmconfigtest.c           | 16 +++++-----------
 3 files changed, 18 insertions(+), 38 deletions(-)

diff --git a/tests/libxlxml2domconfigtest.c b/tests/libxlxml2domconfigtest.c
index 19385c6fb5..2bc5c26223 100644
--- a/tests/libxlxml2domconfigtest.c
+++ b/tests/libxlxml2domconfigtest.c
@@ -53,9 +53,9 @@ testCompareXMLToDomConfig(const char *xmlfile,
     xentoollog_logger *log = NULL;
     virPortAllocatorRange *gports = NULL;
     virDomainDef *vmdef = NULL;
-    char *actualjson = NULL;
-    char *tempjson = NULL;
-    char *expectjson = NULL;
+    g_autofree char *actualjson = NULL;
+    g_autofree char *tempjson = NULL;
+    g_autofree char *expectjson = NULL;
     g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
 
     libxl_domain_config_init(&actualconfig);
@@ -128,9 +128,6 @@ testCompareXMLToDomConfig(const char *xmlfile,
         vmdef->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC)
         virPortAllocatorRelease(vmdef->graphics[0]->data.vnc.port);
 
-    VIR_FREE(expectjson);
-    VIR_FREE(actualjson);
-    VIR_FREE(tempjson);
     virDomainDefFree(vmdef);
     virPortAllocatorRangeFree(gports);
     libxl_domain_config_dispose(&actualconfig);
@@ -150,16 +147,14 @@ testCompareXMLToDomConfigHelper(const void *data)
 {
     int ret = -1;
     const struct testInfo *info = data;
-    char *xmlfile = NULL;
-    char *jsonfile = NULL;
+    g_autofree char *xmlfile = NULL;
+    g_autofree char *jsonfile = NULL;
 
     xmlfile = g_strdup_printf("%s/libxlxml2domconfigdata/%s.xml", abs_srcdir, info->name);
     jsonfile = g_strdup_printf("%s/libxlxml2domconfigdata/%s.json", abs_srcdir, info->name);
 
     ret = testCompareXMLToDomConfig(xmlfile, jsonfile);
 
-    VIR_FREE(xmlfile);
-    VIR_FREE(jsonfile);
     return ret;
 }
 
diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c
index 0a2997b8b6..95ee670b00 100644
--- a/tests/xlconfigtest.c
+++ b/tests/xlconfigtest.c
@@ -45,7 +45,7 @@ static libxlDriverPrivate *driver;
 static char *
 testReplaceVarsXML(const char *xml)
 {
-    char *xmlcfgData;
+    g_autofree char *xmlcfgData = NULL;
     char *replacedXML;
 
     if (virTestLoadFile(xml, &xmlcfgData) < 0)
@@ -54,7 +54,6 @@ testReplaceVarsXML(const char *xml)
     replacedXML = virStringReplace(xmlcfgData, "/LIBXL_FIRMWARE_DIR",
                                    LIBXL_FIRMWARE_DIR);
 
-    VIR_FREE(xmlcfgData);
     return replacedXML;
 }
 
@@ -65,13 +64,13 @@ testReplaceVarsXML(const char *xml)
 static int
 testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars)
 {
-    char *gotxlcfgData = NULL;
+    g_autofree char *gotxlcfgData = NULL;
     g_autoptr(virConf) conf = NULL;
     g_autoptr(virConnect) conn = NULL;
     int wrote = 4096;
     int ret = -1;
     virDomainDef *def = NULL;
-    char *replacedXML = NULL;
+    g_autofree char *replacedXML = NULL;
 
     gotxlcfgData = g_new0(char, wrote);
 
@@ -108,8 +107,6 @@ testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars)
     ret = 0;
 
  fail:
-    VIR_FREE(replacedXML);
-    VIR_FREE(gotxlcfgData);
     virDomainDefFree(def);
 
     return ret;
@@ -122,13 +119,13 @@ testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars)
 static int
 testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars)
 {
-    char *xlcfgData = NULL;
-    char *gotxml = NULL;
+    g_autofree char *xlcfgData = NULL;
+    g_autofree char *gotxml = NULL;
     g_autoptr(virConf) conf = NULL;
     int ret = -1;
     g_autoptr(virConnect) conn = NULL;
     virDomainDef *def = NULL;
-    char *replacedXML = NULL;
+    g_autofree char *replacedXML = NULL;
     g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
 
     conn = virGetConnect();
@@ -161,9 +158,6 @@ testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars)
     ret = 0;
 
  fail:
-    VIR_FREE(replacedXML);
-    VIR_FREE(xlcfgData);
-    VIR_FREE(gotxml);
     virDomainDefFree(def);
 
     return ret;
@@ -181,8 +175,8 @@ testCompareHelper(const void *data)
 {
     int result = -1;
     const struct testInfo *info = data;
-    char *xml = NULL;
-    char *cfg = NULL;
+    g_autofree char *xml = NULL;
+    g_autofree char *cfg = NULL;
 
     xml = g_strdup_printf("%s/xlconfigdata/test-%s.xml", abs_srcdir, info->name);
     cfg = g_strdup_printf("%s/xlconfigdata/test-%s.cfg", abs_srcdir, info->name);
@@ -192,9 +186,6 @@ testCompareHelper(const void *data)
     else
         result = testCompareFormatXML(cfg, xml, info->replaceVars);
 
-    VIR_FREE(xml);
-    VIR_FREE(cfg);
-
     return result;
 }
 
diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c
index 9d5eb85bf9..a756f752f8 100644
--- a/tests/xmconfigtest.c
+++ b/tests/xmconfigtest.c
@@ -39,7 +39,7 @@ static libxlDriverPrivate *driver;
 static int
 testCompareParseXML(const char *xmcfg, const char *xml)
 {
-    char *gotxmcfgData = NULL;
+    g_autofree char *gotxmcfgData = NULL;
     g_autoptr(virConf) conf = NULL;
     int ret = -1;
     g_autoptr(virConnect) conn = NULL;
@@ -73,7 +73,6 @@ testCompareParseXML(const char *xmcfg, const char *xml)
     ret = 0;
 
  fail:
-    VIR_FREE(gotxmcfgData);
     virDomainDefFree(def);
 
     return ret;
@@ -82,8 +81,8 @@ testCompareParseXML(const char *xmcfg, const char *xml)
 static int
 testCompareFormatXML(const char *xmcfg, const char *xml)
 {
-    char *xmcfgData = NULL;
-    char *gotxml = NULL;
+    g_autofree char *xmcfgData = NULL;
+    g_autofree char *gotxml = NULL;
     g_autoptr(virConf) conf = NULL;
     int ret = -1;
     virDomainDef *def = NULL;
@@ -107,8 +106,6 @@ testCompareFormatXML(const char *xmcfg, const char *xml)
     ret = 0;
 
  fail:
-    VIR_FREE(xmcfgData);
-    VIR_FREE(gotxml);
     virDomainDefFree(def);
 
     return ret;
@@ -125,8 +122,8 @@ testCompareHelper(const void *data)
 {
     int result = -1;
     const struct testInfo *info = data;
-    char *xml = NULL;
-    char *cfg = NULL;
+    g_autofree char *xml = NULL;
+    g_autofree char *cfg = NULL;
 
     xml = g_strdup_printf("%s/xmconfigdata/test-%s.xml", abs_srcdir, info->name);
     cfg = g_strdup_printf("%s/xmconfigdata/test-%s.cfg", abs_srcdir, info->name);
@@ -136,9 +133,6 @@ testCompareHelper(const void *data)
     else
         result = testCompareFormatXML(cfg, xml);
 
-    VIR_FREE(xml);
-    VIR_FREE(cfg);
-
     return result;
 }
 
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux