[FFmpeg-cvslog] Make av_realloc(0) behave like our av_malloc(0)
Daniel Verkamp
daniel at drv.nu
Sun May 8 02:18:34 CEST 2011
On Sat, May 7, 2011 at 4:55 PM, Michael Niedermayer <michaelni at gmx.at> wrote:
> On Sat, May 07, 2011 at 04:46:34PM -0700, Daniel Verkamp wrote:
>> On Sat, May 7, 2011 at 4:36 PM, Michael Niedermayer <michaelni at gmx.at> wrote:
>> > On Sat, May 07, 2011 at 11:31:11AM -0700, Daniel Verkamp wrote:
>> >> On Sat, May 7, 2011 at 7:54 AM, Reimar Döffinger
>> >> <Reimar.Doeffinger at gmx.de> wrote:
>> >> >
>> >> >
>> >> > On 7 May 2011, at 16:23, git at videolan.org (Michael Niedermayer) wrote:
>> >> >
>> >> >> ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sat May 7 15:28:07 2011 +0200| [91ff05f6ac5c65a6cd3701d5a7cdcfb6ccfd87e4] | committer: Michael Niedermayer
>> >> >>
>> >> >> Make av_realloc(0) behave like our av_malloc(0)
>> >> >> Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
>> >> >>
>> >> >>> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=91ff05f6ac5c65a6cd3701d5a7cdcfb6ccfd87e4
>> >> >> ---
>> >> >>
>> >> >> libavutil/mem.c | 2 +-
>> >> >> 1 files changed, 1 insertions(+), 1 deletions(-)
>> >> >>
>> >> >> diff --git a/libavutil/mem.c b/libavutil/mem.c
>> >> >> index 965daa9..83e8c35 100644
>> >> >> --- a/libavutil/mem.c
>> >> >> +++ b/libavutil/mem.c
>> >> >> @@ -132,7 +132,7 @@ void *av_realloc(void *ptr, size_t size)
>> >> >> diff= ((char*)ptr)[-1];
>> >> >> return (char*)realloc((char*)ptr - diff, size + diff) + diff;
>> >> >> #else
>> >> >> - return realloc(ptr, size);
>> >> >> + return realloc(ptr, size + !size);
>> >> >> #endif
>> >> >
>> >> > Not sure if it's such a great idea, but I think you could
>> >> > use exactly the same code as in av_malloc to avoid doing
>> >> > something when not necessary.
>> >>
>> >> Isn't realloc(ptr, 0) supposed to be free(ptr), or does that not apply
>> >> to av_realloc?
>> >
>> > I thought so too but couldnt find that requirement in the C spec
>> > The spec says NULL, X should behave like malloc
>> >
>>
>> My reference was SUS:
>> http://pubs.opengroup.org/onlinepubs/007908799/xsh/realloc.html
>
> "If size is 0, either a null pointer or a unique pointer that can be successfully passed to free() is returned."
>
That's not actually the part I meant; see Description:
"If size is 0 and ptr is not a null pointer, the object pointed to is freed."
I think the Return Value section is referring to the case where ptr ==
NULL && size == 0, whereas I meant the case where ptr != NULL && size
== 0, but it's not very clear.
Either way, as Reimar said, the --enable-memalign-hack version already
didn't do the free-on-0-size, so I don't see a problem with just
documenting this behavior and not supporting size=0 free.
> So i think we are compatible to SUS
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
More information about the ffmpeg-cvslog
mailing list