[libvirt] [PATCH 3/4] VIR_FREE: Avoid doing side work in callees

Michal Privoznik mprivozn at redhat.com
Tue Jul 15 12:38:35 UTC 2014


There are just two places where we rely on the fact that VIR_FREE()
macro is without any side effects. In the future, this property of the
macro is going to change, so we need the code to be adjusted to deal
with argument passed to VIR_FREE() being evaluated multiple times.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 src/conf/network_conf.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index ce4d4d8..d60a60e 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -180,8 +180,10 @@ virNetworkDNSTxtDefClear(virNetworkDNSTxtDefPtr def)
 static void
 virNetworkDNSHostDefClear(virNetworkDNSHostDefPtr def)
 {
-    while (def->nnames)
-        VIR_FREE(def->names[--def->nnames]);
+    size_t i;
+
+    for (i = 0; i < def->nnames; i++)
+        VIR_FREE(def->names[i]);
     VIR_FREE(def->names);
 }
 
@@ -197,9 +199,11 @@ virNetworkDNSSrvDefClear(virNetworkDNSSrvDefPtr def)
 static void
 virNetworkDNSDefClear(virNetworkDNSDefPtr def)
 {
+    size_t i;
+
     if (def->forwarders) {
-        while (def->nfwds)
-            VIR_FREE(def->forwarders[--def->nfwds]);
+        for (i = 0; i < def->nfwds; i++)
+            VIR_FREE(def->forwarders[i]);
         VIR_FREE(def->forwarders);
     }
     if (def->txts) {
-- 
1.8.5.5




More information about the libvir-list mailing list