[Ffmpeg-devel] [RFC] another attempt at memalign realloc

Måns Rullgård mru
Thu Dec 7 13:34:26 CET 2006

Reimar D?ffinger said:
> Hello,
> On Thu, Dec 07, 2006 at 12:55:47PM +0100, Michael Niedermayer wrote:
>> > Too bad I can't find any good solution for the
>> > non-memalign-hack case.
>> p= realloc(p, size);
>> if(!((long)p&15))
>>     return p;
>> p2= av_malloc(size);
>> if(p2)
>>     memcpy(p2, p, size);

Won't that overflow either the old or the new buffer?

>> av_free(p);
>> return p2;
>> ?
>> btw, this one with a small modification should work in the memalign-hack
>> case too i think, would simplify the code though it would be slower in the
>> memalign-hack case ...
> Yes, I was thinking about that, and probably it is fine for ffmpeg, but
> it does not meet this part of realloc:
> "If realloc() fails the original block is left untouched".
> If we do it this change, at least we must free p always and say
> "If av_realloc() fails the original block is freed".
> Unless of course I miss something *g*

You're missing a pair of braces.

M?ns Rullg?rd
mru at inprovide.com

More information about the ffmpeg-devel mailing list