[PATCH 1/3] networkcommon_conf: Use g_autofree where possible

Kristina Hanicova khanicov at redhat.com
Tue Feb 23 17:24:39 UTC 2021


Signed-off-by: Kristina Hanicova <khanicov at redhat.com>
---
 src/conf/networkcommon_conf.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/src/conf/networkcommon_conf.c b/src/conf/networkcommon_conf.c
index 26eeb6dbda..e82dbc3d3d 100644
--- a/src/conf/networkcommon_conf.c
+++ b/src/conf/networkcommon_conf.c
@@ -228,9 +228,10 @@ virNetDevIPRouteParseXML(const char *errorDetail,
 
     virNetDevIPRoutePtr def = NULL;
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
-    char *family = NULL;
-    char *address = NULL, *netmask = NULL;
-    char *gateway = NULL;
+    g_autofree char *family = NULL;
+    g_autofree char *address = NULL;
+    g_autofree char *netmask = NULL;
+    g_autofree char *gateway = NULL;
     unsigned long prefix = 0, metric = 0;
     int prefixRc, metricRc;
     bool hasPrefix = false;
@@ -276,10 +277,6 @@ virNetDevIPRouteParseXML(const char *errorDetail,
                                  hasMetric);
 
  cleanup:
-    VIR_FREE(family);
-    VIR_FREE(address);
-    VIR_FREE(netmask);
-    VIR_FREE(gateway);
     return def;
 }
 
@@ -287,7 +284,7 @@ int
 virNetDevIPRouteFormat(virBufferPtr buf,
                        const virNetDevIPRoute *def)
 {
-    char *addr = NULL;
+    g_autofree char *addr = NULL;
 
     virBufferAddLit(buf, "<route");
 
@@ -311,7 +308,6 @@ virNetDevIPRouteFormat(virBufferPtr buf,
     if (!(addr = virSocketAddrFormat(&def->gateway)))
         return -1;
     virBufferAsprintf(buf, " gateway='%s'", addr);
-    VIR_FREE(addr);
 
     if (def->has_metric && def->metric > 0)
         virBufferAsprintf(buf, " metric='%u'", def->metric);
-- 
2.29.2




More information about the libvir-list mailing list