[ovs-dev] [PATCH v2] netflow: Fix memory leak in netflow_unref.

Yunjian Wang wangyunjian at huawei.com
Mon May 22 04:55:00 UTC 2017


The memory leak was triggered each time on calling netflow_unref() with
containing netflow_flows. And flows need to be removed and destroyed.

Signed-off-by: Yunjian Wang <wangyunjian at huawei.com>
---
 ofproto/netflow.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/ofproto/netflow.c b/ofproto/netflow.c
index 55f7814..29c5f3e 100644
--- a/ofproto/netflow.c
+++ b/ofproto/netflow.c
@@ -409,10 +409,17 @@ netflow_ref(const struct netflow *nf_)
 void
 netflow_unref(struct netflow *nf)
 {
+    struct netflow_flow *nf_flow, *next;
+
     if (nf && ovs_refcount_unref_relaxed(&nf->ref_cnt) == 1) {
         atomic_count_dec(&netflow_count);
         collectors_destroy(nf->collectors);
         ofpbuf_uninit(&nf->packet);
+        HMAP_FOR_EACH_SAFE (nf_flow, next, hmap_node, &nf->flows) {
+            hmap_remove(&nf->flows, &nf_flow->hmap_node);
+            free(nf_flow);
+        }
+        hmap_destroy(&nf->flows);
         free(nf);
     }
 }
-- 
1.8.3.1




More information about the dev mailing list