[FFmpeg-devel,V1,4/5] lavfi/dnn/dnn_backend_native: fix memory leak in error path

Submitted by Jun Zhao on Aug. 19, 2019, 1:01 p.m.

Details

Message ID 1566219667-22805-4-git-send-email-mypopydev@gmail.com
State Accepted
Commit 1b0a8e48f1d710800d2bd85795cfb3e93f28ab32
Headers show

Commit Message

Jun Zhao Aug. 19, 2019, 1:01 p.m.
From: Jun Zhao <barryjzhao@tencent.com>

fix memory leak in error path

Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
---
 libavfilter/dnn/dnn_backend_native.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

Comments

Guo, Yejun Aug. 20, 2019, 1:13 a.m.
> -----Original Message-----

> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf Of

> Jun Zhao

> Sent: Monday, August 19, 2019 9:01 PM

> To: ffmpeg-devel@ffmpeg.org

> Cc: Jun Zhao <barryjzhao@tencent.com>

> Subject: [FFmpeg-devel] [PATCH V1 4/5] lavfi/dnn/dnn_backend_native: fix

> memory leak in error path

> 

> From: Jun Zhao <barryjzhao@tencent.com>

> 

> fix memory leak in error path

> 

> Signed-off-by: Jun Zhao <barryjzhao@tencent.com>

> ---

>  libavfilter/dnn/dnn_backend_native.c |    4 ++++

>  1 files changed, 4 insertions(+), 0 deletions(-)

> 

> diff --git a/libavfilter/dnn/dnn_backend_native.c

> b/libavfilter/dnn/dnn_backend_native.c

> index 7b489d0..2619463 100644

> --- a/libavfilter/dnn/dnn_backend_native.c

> +++ b/libavfilter/dnn/dnn_backend_native.c

> @@ -183,6 +183,7 @@ DNNModel *ff_dnn_load_model_native(const char

> *model_filename)

>              if (dnn_size > file_size || conv_params->input_num <= 0 ||

>                  conv_params->output_num <= 0 ||

> conv_params->kernel_size <= 0){

>                  avio_closep(&model_file_context);

> +                av_freep(&conv_params);

>                  ff_dnn_free_model_native(&model);

>                  return NULL;

>              }

> @@ -190,6 +191,9 @@ DNNModel *ff_dnn_load_model_native(const char

> *model_filename)

>              conv_params->biases = av_malloc(conv_params->output_num

> * sizeof(float));

>              if (!conv_params->kernel || !conv_params->biases){

>                  avio_closep(&model_file_context);

> +                av_freep(&conv_params->kernel);

> +                av_freep(&conv_params->biases);

> +                av_freep(&conv_params);

>                  ff_dnn_free_model_native(&model);

>                  return NULL;

>              }


LGTM, thanks.

> --

> 1.7.1

> 

> _______________________________________________

> 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".
mypopy@gmail.com Aug. 20, 2019, 2:01 a.m.
On Tue, Aug 20, 2019 at 9:14 AM Guo, Yejun <yejun.guo@intel.com> wrote:
>
>
>
> > -----Original Message-----
> > From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf Of
> > Jun Zhao
> > Sent: Monday, August 19, 2019 9:01 PM
> > To: ffmpeg-devel@ffmpeg.org
> > Cc: Jun Zhao <barryjzhao@tencent.com>
> > Subject: [FFmpeg-devel] [PATCH V1 4/5] lavfi/dnn/dnn_backend_native: fix
> > memory leak in error path
> >
> > From: Jun Zhao <barryjzhao@tencent.com>
> >
> > fix memory leak in error path
> >
> > Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
> > ---
> >  libavfilter/dnn/dnn_backend_native.c |    4 ++++
> >  1 files changed, 4 insertions(+), 0 deletions(-)
> >
> > diff --git a/libavfilter/dnn/dnn_backend_native.c
> > b/libavfilter/dnn/dnn_backend_native.c
> > index 7b489d0..2619463 100644
> > --- a/libavfilter/dnn/dnn_backend_native.c
> > +++ b/libavfilter/dnn/dnn_backend_native.c
> > @@ -183,6 +183,7 @@ DNNModel *ff_dnn_load_model_native(const char
> > *model_filename)
> >              if (dnn_size > file_size || conv_params->input_num <= 0 ||
> >                  conv_params->output_num <= 0 ||
> > conv_params->kernel_size <= 0){
> >                  avio_closep(&model_file_context);
> > +                av_freep(&conv_params);
> >                  ff_dnn_free_model_native(&model);
> >                  return NULL;
> >              }
> > @@ -190,6 +191,9 @@ DNNModel *ff_dnn_load_model_native(const char
> > *model_filename)
> >              conv_params->biases = av_malloc(conv_params->output_num
> > * sizeof(float));
> >              if (!conv_params->kernel || !conv_params->biases){
> >                  avio_closep(&model_file_context);
> > +                av_freep(&conv_params->kernel);
> > +                av_freep(&conv_params->biases);
> > +                av_freep(&conv_params);
> >                  ff_dnn_free_model_native(&model);
> >                  return NULL;
> >              }
>
> LGTM, thanks.
>
Will apply, Thanks

Patch hide | download patch | download mbox

diff --git a/libavfilter/dnn/dnn_backend_native.c b/libavfilter/dnn/dnn_backend_native.c
index 7b489d0..2619463 100644
--- a/libavfilter/dnn/dnn_backend_native.c
+++ b/libavfilter/dnn/dnn_backend_native.c
@@ -183,6 +183,7 @@  DNNModel *ff_dnn_load_model_native(const char *model_filename)
             if (dnn_size > file_size || conv_params->input_num <= 0 ||
                 conv_params->output_num <= 0 || conv_params->kernel_size <= 0){
                 avio_closep(&model_file_context);
+                av_freep(&conv_params);
                 ff_dnn_free_model_native(&model);
                 return NULL;
             }
@@ -190,6 +191,9 @@  DNNModel *ff_dnn_load_model_native(const char *model_filename)
             conv_params->biases = av_malloc(conv_params->output_num * sizeof(float));
             if (!conv_params->kernel || !conv_params->biases){
                 avio_closep(&model_file_context);
+                av_freep(&conv_params->kernel);
+                av_freep(&conv_params->biases);
+                av_freep(&conv_params);
                 ff_dnn_free_model_native(&model);
                 return NULL;
             }