[ovs-dev] [PATCH 3/4] ofp-port: Fix leak on error path in parse_intel_port_custom_property().

Ben Pfaff blp at ovn.org
Thu Aug 30 20:54:17 UTC 2018


On Thu, Aug 30, 2018 at 01:15:03PM -0700, Ben Pfaff wrote:
> On Mon, Aug 27, 2018 at 04:13:03PM -0700, Yifeng Sun wrote:
> > It seems (struct ofputil_port_stats).custom_stats.counters is still leaked
> > by
> > the below code path even after this fix.
> > 
> > parse_intel_port_custom_property
> > <- ofputil_pull_ofp14_port_stats
> > <- ofputil_decode_port_stats
> > <- ofputil_count_port_stats
> > 
> > I created a diff, how do you like it? Thanks.
> > 
> > diff --git a/lib/ofp-port.c b/lib/ofp-port.c
> > index 8d882a14b..b9ad34dbe 100644
> > --- a/lib/ofp-port.c
> > +++ b/lib/ofp-port.c
> > @@ -1711,7 +1711,9 @@ ofputil_count_port_stats(const struct ofp_header *oh)
> > 
> >      for (size_t n = 0; ; n++) {
> >          struct ofputil_port_stats ps;
> > -        if (ofputil_decode_port_stats(&ps, &b)) {
> > +       int err = ofputil_decode_port_stats(&ps, &b);
> > +       free(ps.custom_stats.counters);
> > +       if (err) {
> >              return n;
> >          }
> >      }
> 
> Thanks, I folded that in.

Actually the freeing should only happen if the decode is successful.

There's other stuff wrong in this area too.

I'll send a v2.


More information about the dev mailing list