On 2014-02-10 14:09:14 +0100, Luca Barbato wrote:
> On 10/02/14 14:03, Janne Grunau wrote:
> > On 2014-02-09 19:28:15 +0100, Luca Barbato wrote:
> >> Plug some leaks and free on non-allocated pointers.
> >> ---
> >> @@ -216,10 +220,21 @@ av_cold int ffv1_init_slice_contexts(FFV1Context *f)
> >>  
> >>          fs->sample_buffer = av_malloc(3 * MAX_PLANES * (fs->width + 6) *
> >>                                        sizeof(*fs->sample_buffer));
> >> -        if (!fs->sample_buffer)
> >> -            return AVERROR(ENOMEM);
> >> +        if (!fs->sample_buffer) {
> >> +            av_freep(f->slice_context + i);
> >> +            goto fail;
> >> +        }
> >>      }
> >>      return 0;
> >> +
> >> +fail:
> >> +    for (j = 0; j < i; j++) {
> >> +        av_free(f->slice_context[i]->sample_buffer);
> >> +        av_freep(f->slice_context + j);
> >> +    }
> >> +    for (; i < f->slice_count; i++)
> >> +        f->slice_context[i] = NULL;
> > 
> > is there a reason to believe that these could be not null?
> 
> Probably we could zero it from start.

it's zero from the start, avctx.priv_data is allocated with av_mallocz

> > The error handling looks imho too complex while technically correct.
> > I would just go over all f->slice_count contexts free
> > f->slice_context[i]->sample_buffer if (f->slice_context[i]) and
> > av_freep() the slice context then.
> 
> I prefer be sure than sorry.

I would say the simpler approach is safer

> > and while identical &f->slice_context[i] is probably easier to read
> 
> I prefer not use &foo[i] when possible because it is less easier to read
> and & could be typoed away too easily.

I disagree but do as you prefer

Janne
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to