diff mbox series

[FFmpeg-devel,5/9] avfilter/vf_subtitles: Fix leaks on failure

Message ID 20200910214901.25401-5-andreas.rheinhardt@gmail.com
State Accepted
Commit 77ace1ffea6bd40d44326c1a87a55db0937877f1
Headers show
Series [FFmpeg-devel,1/9] avfilter/lavfutils: Don't use uninitialized pointers for freeing | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Sept. 10, 2020, 9:48 p.m. UTC
init_subtitles() sometimes returned directly upon error without cleaning
up after itself. The easiest way to trigger this is by using
picture-based subtitles; it is also possible to run into this in case of
missing decoders or allocation failures.

Furthermore, return the proper error code in case of missing decoder.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavfilter/vf_subtitles.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Comments

Paul B Mahol Sept. 11, 2020, 9:16 a.m. UTC | #1
On Thu, Sep 10, 2020 at 11:48:57PM +0200, Andreas Rheinhardt wrote:
> init_subtitles() sometimes returned directly upon error without cleaning
> up after itself. The easiest way to trigger this is by using
> picture-based subtitles; it is also possible to run into this in case of
> missing decoders or allocation failures.
> 
> Furthermore, return the proper error code in case of missing decoder.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavfilter/vf_subtitles.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)

ok

> 
> diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c
> index 1bd42391e0..2d3145bf2d 100644
> --- a/libavfilter/vf_subtitles.c
> +++ b/libavfilter/vf_subtitles.c
> @@ -384,13 +384,15 @@ static av_cold int init_subtitles(AVFilterContext *ctx)
>      if (!dec) {
>          av_log(ctx, AV_LOG_ERROR, "Failed to find subtitle codec %s\n",
>                 avcodec_get_name(st->codecpar->codec_id));
> -        return AVERROR(EINVAL);
> +        ret = AVERROR_DECODER_NOT_FOUND;
> +        goto end;
>      }
>      dec_desc = avcodec_descriptor_get(st->codecpar->codec_id);
>      if (dec_desc && !(dec_desc->props & AV_CODEC_PROP_TEXT_SUB)) {
>          av_log(ctx, AV_LOG_ERROR,
>                 "Only text based subtitles are currently supported\n");
> -        return AVERROR_PATCHWELCOME;
> +        ret = AVERROR_PATCHWELCOME;
> +        goto end;
>      }
>      if (ass->charenc)
>          av_dict_set(&codec_opts, "sub_charenc", ass->charenc, 0);
> @@ -398,8 +400,10 @@ static av_cold int init_subtitles(AVFilterContext *ctx)
>          av_dict_set(&codec_opts, "sub_text_format", "ass", 0);
>  
>      dec_ctx = avcodec_alloc_context3(dec);
> -    if (!dec_ctx)
> -        return AVERROR(ENOMEM);
> +    if (!dec_ctx) {
> +        ret = AVERROR(ENOMEM);
> +        goto end;
> +    }
>  
>      ret = avcodec_parameters_to_context(dec_ctx, st->codecpar);
>      if (ret < 0)
> -- 
> 2.20.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".
Nicolas George Sept. 11, 2020, 9:19 a.m. UTC | #2
Andreas Rheinhardt (12020-09-10):
> init_subtitles() sometimes returned directly upon error without cleaning
> up after itself. The easiest way to trigger this is by using
> picture-based subtitles; it is also possible to run into this in case of
> missing decoders or allocation failures.
> 
> Furthermore, return the proper error code in case of missing decoder.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavfilter/vf_subtitles.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)

LGTM.

Regards,
diff mbox series

Patch

diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c
index 1bd42391e0..2d3145bf2d 100644
--- a/libavfilter/vf_subtitles.c
+++ b/libavfilter/vf_subtitles.c
@@ -384,13 +384,15 @@  static av_cold int init_subtitles(AVFilterContext *ctx)
     if (!dec) {
         av_log(ctx, AV_LOG_ERROR, "Failed to find subtitle codec %s\n",
                avcodec_get_name(st->codecpar->codec_id));
-        return AVERROR(EINVAL);
+        ret = AVERROR_DECODER_NOT_FOUND;
+        goto end;
     }
     dec_desc = avcodec_descriptor_get(st->codecpar->codec_id);
     if (dec_desc && !(dec_desc->props & AV_CODEC_PROP_TEXT_SUB)) {
         av_log(ctx, AV_LOG_ERROR,
                "Only text based subtitles are currently supported\n");
-        return AVERROR_PATCHWELCOME;
+        ret = AVERROR_PATCHWELCOME;
+        goto end;
     }
     if (ass->charenc)
         av_dict_set(&codec_opts, "sub_charenc", ass->charenc, 0);
@@ -398,8 +400,10 @@  static av_cold int init_subtitles(AVFilterContext *ctx)
         av_dict_set(&codec_opts, "sub_text_format", "ass", 0);
 
     dec_ctx = avcodec_alloc_context3(dec);
-    if (!dec_ctx)
-        return AVERROR(ENOMEM);
+    if (!dec_ctx) {
+        ret = AVERROR(ENOMEM);
+        goto end;
+    }
 
     ret = avcodec_parameters_to_context(dec_ctx, st->codecpar);
     if (ret < 0)