[Libav-user] Magic Realloc

Ingo Foerster foerster at ifoerster.com
Wed Mar 12 02:11:26 CET 2014


I updated to newest ffmpeg and now I run into a problem. It seems that
ffmpeg  do  a  magic  realloc  and  so I get strange problems with the

I use:

        unsigned char *bit_buffer;

        bit_buffer = (unsigned char *)av_malloc(2048 * 32 * 2 + FF_INPUT_BUFFER_PADDING_SIZE);
        bit_buffer_size = 2048 * 32;

        AVIOContext *avIO = avio_alloc_context(bit_buffer, bit_buffer_size, 0, cryPut, cryPut->read, NULL, NULL);//cryPut->seek);
        avIO->seekable = 0;

        input_file = avformat_alloc_context();
        input_file->pb = avIO;
        int ret;
        if((ret = avformat_open_input(&input_file, "", NULL, NULL)) < 0) 
                char desc[1024];
                int ret2 = av_strerror(ret, desc, 1024);
                return -1;

No   I  see  in  the  stack that ffmpeg do a realloc. After this it is
possible  to  free  the  buffer: if(bit_buffer) { av_free(bit_buffer);
bit_buffer = NULL; } <--- Bad crash.

So  how  act  ffmpeg  here?  Normaly  a  realloc create a pointer to a
pointer and handle the free/delete itself. But if I do not use av_free
then I have a big memleak. Any idea?



More information about the Libav-user mailing list