[FFmpeg-devel] [PATCH 1/5] avformat/iamf_writer: Don't leak on error when adding ParamDefinition

James Almer jamrial at gmail.com
Tue Feb 20 00:19:40 EET 2024


On 2/19/2024 6:51 PM, Andreas Rheinhardt wrote:
> Fix this by postponing the allocation.
> Fixes Coverity issue #1559545.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> ---
>   libavformat/iamf_writer.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/libavformat/iamf_writer.c b/libavformat/iamf_writer.c
> index 1a360dee2f..897b06310f 100644
> --- a/libavformat/iamf_writer.c
> +++ b/libavformat/iamf_writer.c
> @@ -138,10 +138,6 @@ static IAMFParamDefinition *add_param_definition(IAMFContext *iamf, AVIAMFParamD
>   
>       iamf->param_definitions = tmp;
>   
> -    param_definition = av_mallocz(sizeof(*param_definition));
> -    if (!param_definition)
> -        return NULL;
> -
>       if (audio_element)
>           codec_config = iamf->codec_configs[audio_element->codec_config_id];
>   
> @@ -160,6 +156,10 @@ static IAMFParamDefinition *add_param_definition(IAMFContext *iamf, AVIAMFParamD
>               param->constant_subblock_duration = codec_config->nb_samples;
>       }
>   
> +    param_definition = av_mallocz(sizeof(*param_definition));
> +    if (!param_definition)
> +        return NULL;
> +
>       param_definition->mode = !!param->duration;
>       param_definition->param = param;
>       param_definition->audio_element = audio_element;

LGTM


More information about the ffmpeg-devel mailing list