diff mbox series

[FFmpeg-devel] avformat/movenccenc: Fix memory leak for muxing CENC-encrypted files

Message ID 20210131145245.15161-1-vadim.bezdush@gmail.com
State Accepted
Commit bc04ea39a57a22dd4d26946a83e166f090218054
Headers show
Series [FFmpeg-devel] avformat/movenccenc: Fix memory leak for muxing CENC-encrypted files | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Вадим Бездушный Jan. 31, 2021, 2:52 p.m. UTC
Signed-off-by: Vadym Bezdushnyi <vadim.bezdush@gmail.com>
---
Memory for auxillary_info was not freed after usage.

Leak can be reproduced with following commands:

Optionally, generate input video:
ffmpeg -f lavfi -i testsrc=duration=10:size=1280x720:rate=30 input.mp4

Run ffmpeg with valgrind:
valgrind --leak-check=full --show-leak-kinds=all \
ffmpeg -y -i input.mp4 -vcodec copy -acodec copy \
-encryption_scheme cenc-aes-ctr \
-encryption_key 00000000000000000000000000000000 \
-encryption_kid 00000000000000000000000000000000 \
ffmpeg_encrypted.mp4

For test video which has duration of 10 sec, leak is 4 Kb.
For 100 sec video, leak will be 33 Kb. Most likely,
leaked memory will grow linearly to the number of input frames.

 libavformat/movenccenc.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Вадим Бездушный Feb. 27, 2021, 5:53 p.m. UTC | #1
Ping.

This patch is very trivial and solves memory leak which makes CENC
encryption quite hard to use on high load services.

вс, 31 янв. 2021 г. в 16:52, Vadym Bezdushnyi <vadim.bezdush@gmail.com>:

> Signed-off-by: Vadym Bezdushnyi <vadim.bezdush@gmail.com>
> ---
> Memory for auxillary_info was not freed after usage.
>
> Leak can be reproduced with following commands:
>
> Optionally, generate input video:
> ffmpeg -f lavfi -i testsrc=duration=10:size=1280x720:rate=30 input.mp4
>
> Run ffmpeg with valgrind:
> valgrind --leak-check=full --show-leak-kinds=all \
> ffmpeg -y -i input.mp4 -vcodec copy -acodec copy \
> -encryption_scheme cenc-aes-ctr \
> -encryption_key 00000000000000000000000000000000 \
> -encryption_kid 00000000000000000000000000000000 \
> ffmpeg_encrypted.mp4
>
> For test video which has duration of 10 sec, leak is 4 Kb.
> For 100 sec video, leak will be 33 Kb. Most likely,
> leaked memory will grow linearly to the number of input frames.
>
>  libavformat/movenccenc.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/libavformat/movenccenc.c b/libavformat/movenccenc.c
> index b91294f706..74f3c4ccfb 100644
> --- a/libavformat/movenccenc.c
> +++ b/libavformat/movenccenc.c
> @@ -412,4 +412,6 @@ int ff_mov_cenc_init(MOVMuxCencContext* ctx, uint8_t*
> encryption_key,
>  void ff_mov_cenc_free(MOVMuxCencContext* ctx)
>  {
>      av_aes_ctr_free(ctx->aes_ctr);
> +    av_freep(&ctx->auxiliary_info);
> +    av_freep(&ctx->auxiliary_info_sizes);
>  }
> --
> 2.30.0
>
>
Marton Balint Feb. 27, 2021, 9:14 p.m. UTC | #2
On Sat, 27 Feb 2021, Вадим Бездушный wrote:

> Ping.
>
> This patch is very trivial and solves memory leak which makes CENC
> encryption quite hard to use on high load services.

Thanks, applied.

Regards,
Marton

>
> вс, 31 янв. 2021 г. в 16:52, Vadym Bezdushnyi <vadim.bezdush@gmail.com>:
>
>> Signed-off-by: Vadym Bezdushnyi <vadim.bezdush@gmail.com>
>> ---
>> Memory for auxillary_info was not freed after usage.
>>
>> Leak can be reproduced with following commands:
>>
>> Optionally, generate input video:
>> ffmpeg -f lavfi -i testsrc=duration=10:size=1280x720:rate=30 input.mp4
>>
>> Run ffmpeg with valgrind:
>> valgrind --leak-check=full --show-leak-kinds=all \
>> ffmpeg -y -i input.mp4 -vcodec copy -acodec copy \
>> -encryption_scheme cenc-aes-ctr \
>> -encryption_key 00000000000000000000000000000000 \
>> -encryption_kid 00000000000000000000000000000000 \
>> ffmpeg_encrypted.mp4
>>
>> For test video which has duration of 10 sec, leak is 4 Kb.
>> For 100 sec video, leak will be 33 Kb. Most likely,
>> leaked memory will grow linearly to the number of input frames.
>>
>>  libavformat/movenccenc.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/libavformat/movenccenc.c b/libavformat/movenccenc.c
>> index b91294f706..74f3c4ccfb 100644
>> --- a/libavformat/movenccenc.c
>> +++ b/libavformat/movenccenc.c
>> @@ -412,4 +412,6 @@ int ff_mov_cenc_init(MOVMuxCencContext* ctx, uint8_t*
>> encryption_key,
>>  void ff_mov_cenc_free(MOVMuxCencContext* ctx)
>>  {
>>      av_aes_ctr_free(ctx->aes_ctr);
>> +    av_freep(&ctx->auxiliary_info);
>> +    av_freep(&ctx->auxiliary_info_sizes);
>>  }
>> --
>> 2.30.0
>>
>>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavformat/movenccenc.c b/libavformat/movenccenc.c
index b91294f706..74f3c4ccfb 100644
--- a/libavformat/movenccenc.c
+++ b/libavformat/movenccenc.c
@@ -412,4 +412,6 @@  int ff_mov_cenc_init(MOVMuxCencContext* ctx, uint8_t* encryption_key,
 void ff_mov_cenc_free(MOVMuxCencContext* ctx)
 {
     av_aes_ctr_free(ctx->aes_ctr);
+    av_freep(&ctx->auxiliary_info);
+    av_freep(&ctx->auxiliary_info_sizes);
 }