[Libav-user] Magic Realloc

Hendrik Leppkes h.leppkes at gmail.com
Wed Mar 12 08:54:58 CET 2014


On Wed, Mar 12, 2014 at 2:11 AM, Ingo Foerster <foerster at ifoerster.com> wrote:
> Hello,
>
> 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
> buffer.
>
> 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?
>

You can free avIO->buffer, it always points to the re-allocated version.
Even saves you tracking of one variable. :)

- Hendrik


More information about the Libav-user mailing list