[FFmpeg-devel] [PATCH] avformat/mov: fix memleak

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Mon Jun 29 23:46:09 EEST 2020


Zhao Zhili:
> Remove the check on dv_demux since dv_fctx will leak if allocate
> dv_demux failed.
> ---
>  libavformat/mov.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index adc52de947..f179b6efdd 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -7357,10 +7357,9 @@ static int mov_read_close(AVFormatContext *s)
>          av_freep(&sc->coll);
>      }
>  
> -    if (mov->dv_demux) {
> -        avformat_free_context(mov->dv_fctx);
> -        mov->dv_fctx = NULL;
> -    }
> +    av_freep(&mov->dv_demux);
> +    avformat_free_context(mov->dv_fctx);
> +    mov->dv_fctx = NULL;
>  
>      if (mov->meta_keys) {
>          for (i = 1; i < mov->meta_keys_count; i++) {
> 

I found samples [1] to test the dv audio codepath; it indeed showed two
kinds of leaks: The leaks of AVBufferRef and AVBuffer per packet (fixed
by my patch) and the leak of the DVDemuxContext (fixed by your patch).
The latter leak is a regression since
edb1af7c466ebb28bfdb0c076e498e527b43d24f.

I intend to apply the two patches in two days if there are no objections
from other devs (or if the maintainer of mov.c doesn't do it earlier).

- Andreas

[1]: Use the samples from
http://samples.ffmpeg.org/ffmpeg-bugs/trac/ticket4671/dir1.tar.bz2
together with the enable_drefs option set.


More information about the ffmpeg-devel mailing list