diff mbox series

[FFmpeg-devel,07/21] avfilter/af_afir: Fix leak of AVFilterChannelLayout in case of error

Message ID 20200809155748.30092-1-andreas.rheinhardt@gmail.com
State Accepted
Commit 3a0f080ffa5185f45850f15e5e7b8cf997337bf7
Headers show
Series [FFmpeg-devel,1/6] avfilter/formats: Remove ff_make_formatu64_list()
Related show

Checks

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

Commit Message

Andreas Rheinhardt Aug. 9, 2020, 3:57 p.m. UTC
If an error happens between the allocation of an AVFilterChannelLayout
and its usage (which involves attaching said object to a more permanent
object), the channel layout array leaks. This can simply be fixed by
making sure that nothing is between the allocation and the
aforementioned usage.

Fixes Coverity issue #1250334.

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

Comments

Andreas Rheinhardt Aug. 18, 2020, 7:15 p.m. UTC | #1
Andreas Rheinhardt:
> If an error happens between the allocation of an AVFilterChannelLayout
> and its usage (which involves attaching said object to a more permanent
> object), the channel layout array leaks. This can simply be fixed by
> making sure that nothing is between the allocation and the
> aforementioned usage.
> 
> Fixes Coverity issue #1250334.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavfilter/af_afir.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/libavfilter/af_afir.c b/libavfilter/af_afir.c
> index 5ba880f10b..6cbc7a00a1 100644
> --- a/libavfilter/af_afir.c
> +++ b/libavfilter/af_afir.c
> @@ -742,14 +742,14 @@ static int query_formats(AVFilterContext *ctx)
>      } else {
>          AVFilterChannelLayouts *mono = NULL;
>  
> -        ret = ff_add_channel_layout(&mono, AV_CH_LAYOUT_MONO);
> -        if (ret)
> -            return ret;
> -
>          if ((ret = ff_channel_layouts_ref(layouts, &ctx->inputs[0]->out_channel_layouts)) < 0)
>              return ret;
>          if ((ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts)) < 0)
>              return ret;
> +
> +        ret = ff_add_channel_layout(&mono, AV_CH_LAYOUT_MONO);
> +        if (ret)
> +            return ret;
>          for (int i = 1; i < ctx->nb_inputs; i++) {
>              if ((ret = ff_channel_layouts_ref(mono, &ctx->inputs[i]->out_channel_layouts)) < 0)
>                  return ret;
> 
Ping for this and the other outstanding patches of this patchset.

- Andreas
Paul B Mahol Aug. 18, 2020, 7:18 p.m. UTC | #2
On 8/18/20, Andreas Rheinhardt <andreas.rheinhardt@gmail.com> wrote:
> Andreas Rheinhardt:
>> If an error happens between the allocation of an AVFilterChannelLayout
>> and its usage (which involves attaching said object to a more permanent
>> object), the channel layout array leaks. This can simply be fixed by
>> making sure that nothing is between the allocation and the
>> aforementioned usage.
>>
>> Fixes Coverity issue #1250334.
>>
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
>> ---
>>  libavfilter/af_afir.c | 8 ++++----
>>  1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/libavfilter/af_afir.c b/libavfilter/af_afir.c
>> index 5ba880f10b..6cbc7a00a1 100644
>> --- a/libavfilter/af_afir.c
>> +++ b/libavfilter/af_afir.c
>> @@ -742,14 +742,14 @@ static int query_formats(AVFilterContext *ctx)
>>      } else {
>>          AVFilterChannelLayouts *mono = NULL;
>>
>> -        ret = ff_add_channel_layout(&mono, AV_CH_LAYOUT_MONO);
>> -        if (ret)
>> -            return ret;
>> -
>>          if ((ret = ff_channel_layouts_ref(layouts,
>> &ctx->inputs[0]->out_channel_layouts)) < 0)
>>              return ret;
>>          if ((ret = ff_channel_layouts_ref(layouts,
>> &ctx->outputs[0]->in_channel_layouts)) < 0)
>>              return ret;
>> +
>> +        ret = ff_add_channel_layout(&mono, AV_CH_LAYOUT_MONO);
>> +        if (ret)
>> +            return ret;
>>          for (int i = 1; i < ctx->nb_inputs; i++) {
>>              if ((ret = ff_channel_layouts_ref(mono,
>> &ctx->inputs[i]->out_channel_layouts)) < 0)
>>                  return ret;
>>
> Ping for this and the other outstanding patches of this patchset.

LGTM

>
> - Andreas
> _______________________________________________
> 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/libavfilter/af_afir.c b/libavfilter/af_afir.c
index 5ba880f10b..6cbc7a00a1 100644
--- a/libavfilter/af_afir.c
+++ b/libavfilter/af_afir.c
@@ -742,14 +742,14 @@  static int query_formats(AVFilterContext *ctx)
     } else {
         AVFilterChannelLayouts *mono = NULL;
 
-        ret = ff_add_channel_layout(&mono, AV_CH_LAYOUT_MONO);
-        if (ret)
-            return ret;
-
         if ((ret = ff_channel_layouts_ref(layouts, &ctx->inputs[0]->out_channel_layouts)) < 0)
             return ret;
         if ((ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts)) < 0)
             return ret;
+
+        ret = ff_add_channel_layout(&mono, AV_CH_LAYOUT_MONO);
+        if (ret)
+            return ret;
         for (int i = 1; i < ctx->nb_inputs; i++) {
             if ((ret = ff_channel_layouts_ref(mono, &ctx->inputs[i]->out_channel_layouts)) < 0)
                 return ret;