[libvirt] [PATCH v3] nwfilter: Don't leak @inetaddr

ZhiPeng Lu lu.zhipeng at zte.com.cn
Wed Sep 27 01:01:39 UTC 2017


In learnIPAddressThread()the @inetaddr may be leaked.

Signed-off-by: ZhiPeng Lu <lu.zhipeng at zte.com.cn>
---
 src/nwfilter/nwfilter_learnipaddr.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c
index cfd92d9..0cadf73 100644
--- a/src/nwfilter/nwfilter_learnipaddr.c
+++ b/src/nwfilter/nwfilter_learnipaddr.c
@@ -605,6 +605,7 @@ learnIPAddressThread(void *arg)
 
     if (req->status == 0) {
         int ret;
+        int mapipret = -1;
         virSocketAddr sa;
         sa.len = sizeof(sa.data.inet4);
         sa.data.inet4.sin_family = AF_INET;
@@ -622,7 +623,7 @@ learnIPAddressThread(void *arg)
         virNWFilterUnlockIface(req->ifname);
 
         if ((inetaddr = virSocketAddrFormat(&sa)) != NULL) {
-            if (virNWFilterIPAddrMapAddIPAddr(req->ifname, inetaddr) < 0) {
+            if ((mapipret = virNWFilterIPAddrMapAddIPAddr(req->ifname, inetaddr)) < 0) {
                 VIR_ERROR(_("Failed to add IP address %s to IP address "
                           "cache for interface %s"), inetaddr, req->ifname);
             }
@@ -637,6 +638,9 @@ learnIPAddressThread(void *arg)
                                                    req->filterparams);
             VIR_DEBUG("Result from applying firewall rules on "
                       "%s with IP addr %s : %d", req->ifname, inetaddr, ret);
+            if (mapipret < 0)
+                VIR_FREE(inetaddr);
+
         }
     } else {
         if (showError)
-- 
1.8.3.1




More information about the libvir-list mailing list