diff mbox series

[FFmpeg-devel,14/23] dnn/dnn_backend_native_layer_conv2d: Fix memleak on realloc failure

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

Commit Message

Andreas Rheinhardt March 10, 2021, 9:54 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavfilter/dnn/dnn_backend_native_layer_conv2d.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Guo, Yejun March 11, 2021, 2:43 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 14/23]
> dnn/dnn_backend_native_layer_conv2d: Fix memleak on realloc failure
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavfilter/dnn/dnn_backend_native_layer_conv2d.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c
> b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c
> index b5c2c394ef..2b83896da9 100644
> --- a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c
> +++ b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c
> @@ -197,6 +197,7 @@ int ff_dnn_execute_layer_conv2d(DnnOperand
> *operands, const int32_t *input_opera
>      int width = operands[input_operand_indexes[0]].dims[2];
>      int pad_size = (conv_params->padding_method == VALID) ?
> (conv_params->kernel_size - 1) / 2 * conv_params->dilation : 0;
>      DnnOperand *output_operand = &operands[output_operand_index];
> +    void *tmp;
> 
>      output_operand->dims[0] =
> operands[input_operand_indexes[0]].dims[0];
>      output_operand->dims[1] = height - pad_size * 2; @@ -208,11 +209,12
> @@ int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t
> *input_opera
>          av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n");
>          return DNN_ERROR;
>      }
> -    output_operand->data = av_realloc(output_operand->data,
> output_operand->length);
> -    if (!output_operand->data) {
> +    tmp = av_realloc(output_operand->data, output_operand->length);
> +    if (!tmp) {
>          av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for
> output\n");
>          return DNN_ERROR;
>      }
> +    output_operand->data = tmp;
LGTM, thanks.
diff mbox series

Patch

diff --git a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c
index b5c2c394ef..2b83896da9 100644
--- a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c
+++ b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c
@@ -197,6 +197,7 @@  int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera
     int width = operands[input_operand_indexes[0]].dims[2];
     int pad_size = (conv_params->padding_method == VALID) ? (conv_params->kernel_size - 1) / 2 * conv_params->dilation : 0;
     DnnOperand *output_operand = &operands[output_operand_index];
+    void *tmp;
 
     output_operand->dims[0] = operands[input_operand_indexes[0]].dims[0];
     output_operand->dims[1] = height - pad_size * 2;
@@ -208,11 +209,12 @@  int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera
         av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n");
         return DNN_ERROR;
     }
-    output_operand->data = av_realloc(output_operand->data, output_operand->length);
-    if (!output_operand->data) {
+    tmp = av_realloc(output_operand->data, output_operand->length);
+    if (!tmp) {
         av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n");
         return DNN_ERROR;
     }
+    output_operand->data = tmp;
     thread_common_param.output_data = output_operand->data;
     thread_common_param.operands = operands;
     thread_common_param.input_operand_indexes = input_operand_indexes;