[FFmpeg-devel] [PATCH] avformat/aviobuf: realloc memory in ffio_ensure_seekback()

Paul B Mahol onemda at gmail.com
Tue Sep 15 14:56:20 EEST 2020


On Tue, Sep 15, 2020 at 01:39:45PM +0200, Nicolas George wrote:
> Paul B Mahol (12020-09-15):
> > This removes big CPU overhead for demuxing chained ogg streams.
> > 
> > Signed-off-by: Paul B Mahol <onemda at gmail.com>
> > ---
> >  libavformat/aviobuf.c | 5 ++---
> >  1 file changed, 2 insertions(+), 3 deletions(-)
> > 
> > diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
> > index a77517d712..6d01150f66 100644
> > --- a/libavformat/aviobuf.c
> > +++ b/libavformat/aviobuf.c
> > @@ -1005,12 +1005,11 @@ int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
> >          return 0;
> >      av_assert0(!s->write_flag);
> >  
> > -    buffer = av_malloc(buf_size);
> > +    buffer = s->buffer;
> 
> > +    buffer = av_realloc(buffer, buf_size);
> >      if (!buffer)
> >          return AVERROR(ENOMEM);
> 
> Leaks in case of failure.

It leaks nothing in case of failure.
In case of failure old memory is kept and
seeking back will fail and thus give errors when syncing.

> 
> >  
> > -    memcpy(buffer, s->buffer, filled);
> > -    av_free(s->buffer);
> >      s->buf_ptr = buffer + (s->buf_ptr - s->buffer);
> >      s->buf_end = buffer + (s->buf_end - s->buffer);
> >      s->buffer = buffer;
> 
> -- 
>   Nicolas George



> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".



More information about the ffmpeg-devel mailing list