diff mbox series

[FFmpeg-devel,05/10] avformat/hls: fix leak of variant when dynarray_add fail

Message ID tencent_0AAD854C731AE84613E4137635C729084E05@qq.com
State New
Headers show
Series [FFmpeg-devel,01/10] avformat/hls: fix repeated requests for media init section | 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

Commit Message

zhilizhao(赵志立) April 12, 2022, 8:15 a.m. UTC
---
 libavformat/hls.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

Steven Liu April 12, 2022, 8:42 a.m. UTC | #1
Zhao Zhili <quinkblack@foxmail.com> 于2022年4月12日周二 16:16写道:
>
> ---
>  libavformat/hls.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/hls.c b/libavformat/hls.c
> index d5c3009d07..b5cdf158c6 100644
> --- a/libavformat/hls.c
> +++ b/libavformat/hls.c
> @@ -366,8 +366,16 @@ static struct variant *new_variant(HLSContext *c, struct variant_info *info,
>          strcpy(var->subtitles_group, info->subtitles);
>      }
>
> -    dynarray_add(&c->variants, &c->n_variants, var);
> -    dynarray_add(&var->playlists, &var->n_playlists, pls);
> +    if (av_dynarray_add_nofree(&var->playlists, &var->n_playlists, pls) < 0) {
> +        /* Don't free pls since it's not owned by variant */
> +        av_free(var);
> +        return NULL;
> +    }
> +    if (av_dynarray_add_nofree(&c->variants, &c->n_variants, var) < 0) {
> +        av_free(var->playlists);
> +        av_free(var);
Why don't use av_freep about these contexts?
> +        return NULL;
> +    }
>      return var;
>  }
>
> --
> 2.31.1
>
> _______________________________________________
> 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".

Thanks
Steven
zhilizhao(赵志立) April 12, 2022, 8:56 a.m. UTC | #2
> On Apr 12, 2022, at 4:42 PM, Steven Liu <lingjiujianke@gmail.com> wrote:
> 
> Zhao Zhili <quinkblack@foxmail.com> 于2022年4月12日周二 16:16写道:
>> 
>> ---
>> libavformat/hls.c | 12 ++++++++++--
>> 1 file changed, 10 insertions(+), 2 deletions(-)
>> 
>> diff --git a/libavformat/hls.c b/libavformat/hls.c
>> index d5c3009d07..b5cdf158c6 100644
>> --- a/libavformat/hls.c
>> +++ b/libavformat/hls.c
>> @@ -366,8 +366,16 @@ static struct variant *new_variant(HLSContext *c, struct variant_info *info,
>>         strcpy(var->subtitles_group, info->subtitles);
>>     }
>> 
>> -    dynarray_add(&c->variants, &c->n_variants, var);
>> -    dynarray_add(&var->playlists, &var->n_playlists, pls);
>> +    if (av_dynarray_add_nofree(&var->playlists, &var->n_playlists, pls) < 0) {
>> +        /* Don't free pls since it's not owned by variant */
>> +        av_free(var);
>> +        return NULL;
>> +    }
>> +    if (av_dynarray_add_nofree(&c->variants, &c->n_variants, var) < 0) {
>> +        av_free(var->playlists);
>> +        av_free(var);
> Why don't use av_freep about these contexts?

It’s a local variable, won’t outlive any longer, so use after free not gone happen.

>> +        return NULL;
>> +    }
>>     return var;
>> }
>> 
>> --
>> 2.31.1
>> 
>> _______________________________________________
>> 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".
> 
> Thanks
> Steven
> _______________________________________________
> 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/hls.c b/libavformat/hls.c
index d5c3009d07..b5cdf158c6 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -366,8 +366,16 @@  static struct variant *new_variant(HLSContext *c, struct variant_info *info,
         strcpy(var->subtitles_group, info->subtitles);
     }
 
-    dynarray_add(&c->variants, &c->n_variants, var);
-    dynarray_add(&var->playlists, &var->n_playlists, pls);
+    if (av_dynarray_add_nofree(&var->playlists, &var->n_playlists, pls) < 0) {
+        /* Don't free pls since it's not owned by variant */
+        av_free(var);
+        return NULL;
+    }
+    if (av_dynarray_add_nofree(&c->variants, &c->n_variants, var) < 0) {
+        av_free(var->playlists);
+        av_free(var);
+        return NULL;
+    }
     return var;
 }