[FFmpeg-cvslog] avformat/iamf_writer: Don't leak on error when adding ParamDefinition

Andreas Rheinhardt git at videolan.org
Tue Feb 20 00:39:03 EET 2024


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Mon Feb 19 19:10:09 2024 +0100| [94fadd335bd1405b6fad7c8d0a249c78bd475ff9] | committer: Andreas Rheinhardt

avformat/iamf_writer: Don't leak on error when adding ParamDefinition

Fix this by postponing the allocation.
Fixes Coverity issue #1559545.

Reviewed-by: James Almer <jamrial at gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=94fadd335bd1405b6fad7c8d0a249c78bd475ff9
---

 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;



More information about the ffmpeg-cvslog mailing list