[ovs-dev] [PATCH 1/9] ofproto/trace: Fix memory leak in oftrace_push_ct_state()

Yi-Hung Wei yihung.wei at gmail.com
Fri Aug 25 22:51:11 UTC 2017


Free the allocated memory in the pop function.

Fixes: 0f2f05bbcf743 ("ofproto/trace: Add --ct-next option to ofproto/trace")
Signed-off-by: Yi-Hung Wei <yihung.wei at gmail.com>
---
 ofproto/ofproto-dpif-trace.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/ofproto/ofproto-dpif-trace.c b/ofproto/ofproto-dpif-trace.c
index 38d11002f290..a45c9cfd9619 100644
--- a/ofproto/ofproto-dpif-trace.c
+++ b/ofproto/ofproto-dpif-trace.c
@@ -128,12 +128,14 @@ oftrace_push_ct_state(struct ovs_list *next_ct_states, uint32_t ct_state)
     ovs_list_push_back(next_ct_states, &next_ct_state->node);
 }
 
-static uint32_t
-oftrace_pop_ct_state(struct ovs_list *next_ct_states)
+static void
+oftrace_pop_ct_state(struct ovs_list *next_ct_states, uint32_t *ct_state)
 {
     struct oftrace_next_ct_state *s;
     LIST_FOR_EACH_POP (s, node, next_ct_states) {
-        return s->state;
+        *ct_state = s->state;
+        free(s);
+        return;
     }
     OVS_NOT_REACHED();
 }
@@ -404,7 +406,8 @@ static void
 free_ct_states(struct ovs_list *ct_states)
 {
     while (!ovs_list_is_empty(ct_states)) {
-        oftrace_pop_ct_state(ct_states);
+        uint32_t state;
+        oftrace_pop_ct_state(ct_states, &state);
     }
 }
 
@@ -646,7 +649,7 @@ ofproto_trace(struct ofproto_dpif *ofproto, const struct flow *flow,
                 ds_put_cstr(output, " - resume conntrack with default "
                             "ct_state=trk|new (use --ct-next to customize)");
             } else {
-                ct_state = oftrace_pop_ct_state(next_ct_states);
+                oftrace_pop_ct_state(next_ct_states, &ct_state);
                 struct ds s = DS_EMPTY_INITIALIZER;
                 format_flags(&s, ct_state_to_string, ct_state, '|');
                 ds_put_format(output, " - resume conntrack with ct_state=%s",
-- 
2.7.4



More information about the dev mailing list