diff mbox series

[FFmpeg-devel,22/23] dnn/dnn_backend_native_layer_mathbinary: Fix leak upon error

Message ID 20210310215446.1396386-13-andreas.rheinhardt@gmail.com
State Accepted
Commit 2f056def652e15eea7fed8b32ed32c9e2fc8bf70
Headers show
Series [FFmpeg-devel,1/8] avcodec/cbs: Remove redundant checks for CodedBitstreamContext.codec | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt March 10, 2021, 9:54 p.m. UTC
Fixes Coverity issue #1473568.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 .../dnn/dnn_backend_native_layer_mathbinary.c | 23 +++++++++----------
 1 file changed, 11 insertions(+), 12 deletions(-)

Comments

Guo, Yejun March 11, 2021, 7:59 a.m. UTC | #1
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Andreas Rheinhardt
> Sent: 2021年3月11日 5:55
> To: ffmpeg-devel@ffmpeg.org
> Cc: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> Subject: [FFmpeg-devel] [PATCH 22/23]
> dnn/dnn_backend_native_layer_mathbinary: Fix leak upon error
> 
> Fixes Coverity issue #1473568.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  .../dnn/dnn_backend_native_layer_mathbinary.c | 23 +++++++++----------
>  1 file changed, 11 insertions(+), 12 deletions(-)
> 
> diff --git a/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c
> b/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c
> index c116188bab..1c33b4633d 100644
> --- a/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c
> +++ b/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c
> @@ -100,20 +100,17 @@ static void math_binary_not_commutative(FunType
> pfun, const DnnLayerMathBinaryPa  }  int
> ff_dnn_load_layer_math_binary(Layer *layer, AVIOContext
> *model_file_context, int file_size, int operands_num)  {
> -    DnnLayerMathBinaryParams *params;
> +    DnnLayerMathBinaryParams params = { 0 };
>      int dnn_size = 0;
>      int input_index = 0;
> -    params = av_malloc(sizeof(*params));
> -    if (!params)
> -        return 0;
> 
> -    params->bin_op = (int32_t)avio_rl32(model_file_context);
> +    params.bin_op = (int32_t)avio_rl32(model_file_context);
>      dnn_size += 4;
> 
> -    params->input0_broadcast = (int32_t)avio_rl32(model_file_context);
> +    params.input0_broadcast = (int32_t)avio_rl32(model_file_context);
>      dnn_size += 4;
> -    if (params->input0_broadcast) {
> -        params->v = av_int2float(avio_rl32(model_file_context));
> +    if (params.input0_broadcast) {
> +        params.v = av_int2float(avio_rl32(model_file_context));
>      } else {
>          layer->input_operand_indexes[input_index] =
> (int32_t)avio_rl32(model_file_context);
>          if (layer->input_operand_indexes[input_index] >= operands_num)
> { @@ -123,10 +120,10 @@ int ff_dnn_load_layer_math_binary(Layer *layer,
> AVIOContext *model_file_context,
>      }
>      dnn_size += 4;
> 
> -    params->input1_broadcast = (int32_t)avio_rl32(model_file_context);
> +    params.input1_broadcast = (int32_t)avio_rl32(model_file_context);
>      dnn_size += 4;
> -    if (params->input1_broadcast) {
> -        params->v = av_int2float(avio_rl32(model_file_context));
> +    if (params.input1_broadcast) {
> +        params.v = av_int2float(avio_rl32(model_file_context));
>      } else {
>          layer->input_operand_indexes[input_index] =
> (int32_t)avio_rl32(model_file_context);
>          if (layer->input_operand_indexes[input_index] >= operands_num)
> { @@ -138,11 +135,13 @@ int ff_dnn_load_layer_math_binary(Layer *layer,
> AVIOContext *model_file_context,
> 
>      layer->output_operand_index = (int32_t)avio_rl32(model_file_context);
>      dnn_size += 4;
> -    layer->params = params;
> 
>      if (layer->output_operand_index >= operands_num) {
>          return 0;
>      }
> +    layer->params = av_memdup(&params, sizeof(params));
> +    if (!layer->params)
> +        return 0;
> 
>      return dnn_size;
>  }

LGTM, thanks.
diff mbox series

Patch

diff --git a/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c b/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c
index c116188bab..1c33b4633d 100644
--- a/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c
+++ b/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c
@@ -100,20 +100,17 @@  static void math_binary_not_commutative(FunType pfun, const DnnLayerMathBinaryPa
 }
 int ff_dnn_load_layer_math_binary(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num)
 {
-    DnnLayerMathBinaryParams *params;
+    DnnLayerMathBinaryParams params = { 0 };
     int dnn_size = 0;
     int input_index = 0;
-    params = av_malloc(sizeof(*params));
-    if (!params)
-        return 0;
 
-    params->bin_op = (int32_t)avio_rl32(model_file_context);
+    params.bin_op = (int32_t)avio_rl32(model_file_context);
     dnn_size += 4;
 
-    params->input0_broadcast = (int32_t)avio_rl32(model_file_context);
+    params.input0_broadcast = (int32_t)avio_rl32(model_file_context);
     dnn_size += 4;
-    if (params->input0_broadcast) {
-        params->v = av_int2float(avio_rl32(model_file_context));
+    if (params.input0_broadcast) {
+        params.v = av_int2float(avio_rl32(model_file_context));
     } else {
         layer->input_operand_indexes[input_index] = (int32_t)avio_rl32(model_file_context);
         if (layer->input_operand_indexes[input_index] >= operands_num) {
@@ -123,10 +120,10 @@  int ff_dnn_load_layer_math_binary(Layer *layer, AVIOContext *model_file_context,
     }
     dnn_size += 4;
 
-    params->input1_broadcast = (int32_t)avio_rl32(model_file_context);
+    params.input1_broadcast = (int32_t)avio_rl32(model_file_context);
     dnn_size += 4;
-    if (params->input1_broadcast) {
-        params->v = av_int2float(avio_rl32(model_file_context));
+    if (params.input1_broadcast) {
+        params.v = av_int2float(avio_rl32(model_file_context));
     } else {
         layer->input_operand_indexes[input_index] = (int32_t)avio_rl32(model_file_context);
         if (layer->input_operand_indexes[input_index] >= operands_num) {
@@ -138,11 +135,13 @@  int ff_dnn_load_layer_math_binary(Layer *layer, AVIOContext *model_file_context,
 
     layer->output_operand_index = (int32_t)avio_rl32(model_file_context);
     dnn_size += 4;
-    layer->params = params;
 
     if (layer->output_operand_index >= operands_num) {
         return 0;
     }
+    layer->params = av_memdup(&params, sizeof(params));
+    if (!layer->params)
+        return 0;
 
     return dnn_size;
 }