[Ffmpeg-devel] [PATCH] av_realloc, unneccesary memcpy and possibly leaks after r5992

Hervé W. H.O.W.aka.V+ffmpeg
Sun Aug 13 23:36:36 CEST 2006


Hi again,

On 13/08/06, Michael Niedermayer wrote:
> On Sun, Aug 13, 2006 at 03:59:54PM +0200, Herv? W. wrote:
[...]
> > >#ifndef MEMALIGN_HACK
> > >    ptr= realloc(ptr, size);
[...]
> the line above is correct and the corresponding change is rejected

I think, I begin to understand. It's correct because the data is
intact. The pointer used in this function might not point to that data
anymore, but the data is still reachable by some pointer that might
exist outside of this function.

[...]
> > >    ptr2= av_malloc(size);
> > >    if(ptr && ptr2)
> > >        memcpy(ptr2, ptr, size);
> > >    av_free(ptr);
> >
> > if ptr2 was NULL, av_free is still called, which in my opinion breaks
> > unnecessarily with "If realloc() fails the original block is left
> > untouched - it is not freed or moved"
> > fixed in: " inputdata disappeared even after failed realloc (part2).diff "
>
> my code is buggy, sadly yours too, it will leak if size=0

You're right. I'm sorry.

> ill try to fix it, dont hesitate to review my change on svnlog and point
> me to any further cases i missed, seems this isnt as easy as it looked

Alright.

Thanks,
-V




More information about the ffmpeg-devel mailing list