diff mbox

[FFmpeg-devel,3/3] avfilter/vf_libopencv: fix resource leak in read_shape_frame_filter

Message ID 20170110114522.7626-1-lq@chinaffmpeg.org
State Accepted
Commit 184c13f64aa5dda7af648cfd8302df3ef8afacc7
Headers show

Commit Message

Liu Steven Jan. 10, 2017, 11:45 a.m. UTC
CID: 1324298
add a label when error goto the label to release resource

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
---
 libavfilter/vf_libopencv.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

Comments

Steven Liu Jan. 11, 2017, 2:01 a.m. UTC | #1
2017-01-10 19:45 GMT+08:00 Steven Liu <lq@chinaffmpeg.org>:

> CID: 1324298
> add a label when error goto the label to release resource
>
> Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
> ---
>  libavfilter/vf_libopencv.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/libavfilter/vf_libopencv.c b/libavfilter/vf_libopencv.c
> index f8ae9d5..8128030 100644
> --- a/libavfilter/vf_libopencv.c
> +++ b/libavfilter/vf_libopencv.c
> @@ -157,7 +157,8 @@ static int read_shape_from_file(int *cols, int *rows,
> int **values, const char *
>          if (buf[i] == '\n') {
>              if (*rows == INT_MAX) {
>                  av_log(log_ctx, AV_LOG_ERROR, "Overflow on the number of
> rows in the file\n");
> -                return AVERROR_INVALIDDATA;
> +                ret = AVERROR_INVALIDDATA;
> +                goto end;
>              }
>              ++(*rows);
>              *cols = FFMAX(*cols, w);
> @@ -171,10 +172,13 @@ static int read_shape_from_file(int *cols, int
> *rows, int **values, const char *
>      if (*rows > (SIZE_MAX / sizeof(int) / *cols)) {
>          av_log(log_ctx, AV_LOG_ERROR, "File with size %dx%d is too big\n",
>                 *rows, *cols);
> -        return AVERROR_INVALIDDATA;
> +        ret = AVERROR_INVALIDDATA;
> +        goto end;
> +    }
> +    if (!(*values = av_mallocz_array(sizeof(int) * *rows, *cols))) {
> +        ret = AVERROR(ENOMEM);
> +        goto end;
>      }
> -    if (!(*values = av_mallocz_array(sizeof(int) * *rows, *cols)))
> -        return AVERROR(ENOMEM);
>
>      /* fill *values */
>      p    = buf;
> @@ -188,6 +192,8 @@ static int read_shape_from_file(int *cols, int *rows,
> int **values, const char *
>                  (*values)[*cols*i + j] = !!av_isgraph(*(p++));
>          }
>      }
> +
> +end:
>      av_file_unmap(buf, size);
>
>  #ifdef DEBUG
> --
> 2.10.1.382.ga23ca1b.dirty
>
>
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

applied!



Thanks
diff mbox

Patch

diff --git a/libavfilter/vf_libopencv.c b/libavfilter/vf_libopencv.c
index f8ae9d5..8128030 100644
--- a/libavfilter/vf_libopencv.c
+++ b/libavfilter/vf_libopencv.c
@@ -157,7 +157,8 @@  static int read_shape_from_file(int *cols, int *rows, int **values, const char *
         if (buf[i] == '\n') {
             if (*rows == INT_MAX) {
                 av_log(log_ctx, AV_LOG_ERROR, "Overflow on the number of rows in the file\n");
-                return AVERROR_INVALIDDATA;
+                ret = AVERROR_INVALIDDATA;
+                goto end;
             }
             ++(*rows);
             *cols = FFMAX(*cols, w);
@@ -171,10 +172,13 @@  static int read_shape_from_file(int *cols, int *rows, int **values, const char *
     if (*rows > (SIZE_MAX / sizeof(int) / *cols)) {
         av_log(log_ctx, AV_LOG_ERROR, "File with size %dx%d is too big\n",
                *rows, *cols);
-        return AVERROR_INVALIDDATA;
+        ret = AVERROR_INVALIDDATA;
+        goto end;
+    }
+    if (!(*values = av_mallocz_array(sizeof(int) * *rows, *cols))) {
+        ret = AVERROR(ENOMEM);
+        goto end;
     }
-    if (!(*values = av_mallocz_array(sizeof(int) * *rows, *cols)))
-        return AVERROR(ENOMEM);
 
     /* fill *values */
     p    = buf;
@@ -188,6 +192,8 @@  static int read_shape_from_file(int *cols, int *rows, int **values, const char *
                 (*values)[*cols*i + j] = !!av_isgraph(*(p++));
         }
     }
+
+end:
     av_file_unmap(buf, size);
 
 #ifdef DEBUG