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

Ben Pfaff blp at ovn.org
Tue Oct 31 22:18:20 UTC 2017


On Fri, Aug 25, 2017 at 03:51:11PM -0700, Yi-Hung Wei wrote:
> 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();
>  }

Thanks for the fix!

I don't understand why the function return type needs to change.  Can
you change this to preserve the return type, while fixing the memory
leak?

Thanks,

Ben.


More information about the dev mailing list