diff mbox series

[FFmpeg-devel] avcodec/libdavs2: workaround memory leak

Message ID tencent_DA5AE235F1803A35933ED756C59C34E04A09@qq.com
State Accepted
Commit 066368e8373d18b496203fa91d98bf11a9b7f59f
Headers show
Series [FFmpeg-devel] avcodec/libdavs2: workaround memory leak | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished

Commit Message

Zhao Zhili June 27, 2022, 9:57 a.m. UTC
davs2_decoder_close doesn't free those on the fly frames which
don't get output yet. It's a design bug, but easy to workaround.

Before the patch:
Direct leak of 1198606 byte(s) in 2 object(s) allocated from:
    #0 0x563af5e1e5f0 in malloc (ffmpeg+0x6675f0)
    #1 0x563af9765ef3 in davs2_malloc davs2/source/common/common.h:1240
    #2 0x563af9765ef3 in davs2_alloc_picture davs2/source/common/header.cc:815

Indirect leak of 3595818 byte(s) in 6 object(s) allocated from:
    #0 0x563af5e1e5f0 in malloc (ffmpeg+0x6675f0)
    #1 0x563af9765ef3 in davs2_malloc davs2/source/common/common.h:1240
    #2 0x563af9765ef3 in davs2_alloc_picture davs2/source/common/header.cc:815

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
---
 libavcodec/libdavs2.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Zhao Zhili July 4, 2022, 3:58 a.m. UTC | #1
> On Jun 27, 2022, at 5:57 PM, Zhao Zhili <quinkblack@foxmail.com> wrote:
> 
> davs2_decoder_close doesn't free those on the fly frames which
> don't get output yet. It's a design bug, but easy to workaround.
> 
> Before the patch:
> Direct leak of 1198606 byte(s) in 2 object(s) allocated from:
>    #0 0x563af5e1e5f0 in malloc (ffmpeg+0x6675f0)
>    #1 0x563af9765ef3 in davs2_malloc davs2/source/common/common.h:1240
>    #2 0x563af9765ef3 in davs2_alloc_picture davs2/source/common/header.cc:815
> 
> Indirect leak of 3595818 byte(s) in 6 object(s) allocated from:
>    #0 0x563af5e1e5f0 in malloc (ffmpeg+0x6675f0)
>    #1 0x563af9765ef3 in davs2_malloc davs2/source/common/common.h:1240
>    #2 0x563af9765ef3 in davs2_alloc_picture davs2/source/common/header.cc:815
> 
> Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
> ---
> libavcodec/libdavs2.c | 1 +
> 1 file changed, 1 insertion(+)
> 
> diff --git a/libavcodec/libdavs2.c b/libavcodec/libdavs2.c
> index d7625718a2..c2040775ae 100644
> --- a/libavcodec/libdavs2.c
> +++ b/libavcodec/libdavs2.c
> @@ -177,6 +177,7 @@ static av_cold int davs2_end(AVCodecContext *avctx)
> 
>     /* close the decoder */
>     if (cad->decoder) {
> +        davs2_flush(avctx);
>         davs2_decoder_close(cad->decoder);
>         cad->decoder = NULL;
>     }
> -- 
> 2.35.3
> 

Applied as 066368e8373d18b496203fa91d98bf11a9b7f59f.
diff mbox series

Patch

diff --git a/libavcodec/libdavs2.c b/libavcodec/libdavs2.c
index d7625718a2..c2040775ae 100644
--- a/libavcodec/libdavs2.c
+++ b/libavcodec/libdavs2.c
@@ -177,6 +177,7 @@  static av_cold int davs2_end(AVCodecContext *avctx)
 
     /* close the decoder */
     if (cad->decoder) {
+        davs2_flush(avctx);
         davs2_decoder_close(cad->decoder);
         cad->decoder = NULL;
     }