[FFmpeg-devel] [PATCH] avcodec/vp56: use av_reallocp_array() and check if allocation fail

Reimar Döffinger Reimar.Doeffinger at gmx.de
Mon Sep 9 20:48:48 CEST 2013


On Mon, Sep 09, 2013 at 04:36:35PM +0000, Carl Eugen Hoyos wrote:
> Paul B Mahol <onemda <at> gmail.com> writes:
> 
> > +    av_reallocp_array(&s->above_blocks, 4*s->mb_width+6,
> > +                      sizeof(*s->above_blocks));
> > +    av_reallocp_array(&s->macroblocks, s->mb_width*s->mb_height,
> > +                      sizeof(*s->macroblocks));
> >      av_free(s->edge_emu_buffer_alloc);
> >      s->edge_emu_buffer_alloc = av_malloc(16*stride);
> > +    if (!s->above_blocks || !s->macroblocks || !s->edge_emu_buffer_alloc)
> > +        return AVERROR(ENOMEM);
> 
> I don't know how likely it is (possibly even impossible) but 
> you could consider fixing the possible memleak.

I _think_ there is no issue. The pointers are all stored in the context,
and will all be freed when the codec is closed.
So it shouldn't matter if we have a mixture of NULL and allocated
pointers after the error check.
Though on the other hand, in principle after a out-of-memory error
it is polite and useful to free any memory we don't have any (immediate)
use for...


More information about the ffmpeg-devel mailing list