[FFmpeg-cvslog] libopencv: Rework error handling in parse_iplconvkernel()

Vittorio Giovara git at videolan.org
Tue Jan 27 20:54:17 CET 2015


ffmpeg | branch: master | Vittorio Giovara <vittorio.giovara at gmail.com> | Fri Jan 23 16:15:37 2015 +0000| [8805589b803fab5f362008306319336ac79a3fa7] | committer: Vittorio Giovara

libopencv: Rework error handling in parse_iplconvkernel()

Fix 'values' memory leak in case of error.

CC: libav-stable at libav.org
Bug-Id: CID 739879

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

 libavfilter/vf_libopencv.c |   22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/libavfilter/vf_libopencv.c b/libavfilter/vf_libopencv.c
index bd3d59b..31fad1f 100644
--- a/libavfilter/vf_libopencv.c
+++ b/libavfilter/vf_libopencv.c
@@ -205,7 +205,7 @@ static int parse_iplconvkernel(IplConvKernel **kernel, char *buf, void *log_ctx)
 {
     char shape_filename[128] = "", shape_str[32] = "rect";
     int cols = 0, rows = 0, anchor_x = 0, anchor_y = 0, shape = CV_SHAPE_RECT;
-    int *values = NULL, ret;
+    int *values = NULL, ret = 0;
 
     sscanf(buf, "%dx%d+%dx%d/%32[^=]=%127s", &cols, &rows, &anchor_x, &anchor_y, shape_str, shape_filename);
 
@@ -219,30 +219,36 @@ static int parse_iplconvkernel(IplConvKernel **kernel, char *buf, void *log_ctx)
     } else {
         av_log(log_ctx, AV_LOG_ERROR,
                "Shape unspecified or type '%s' unknown.\n", shape_str);
-        return AVERROR(EINVAL);
+        ret = AVERROR(EINVAL);
+        goto out;
     }
 
     if (rows <= 0 || cols <= 0) {
         av_log(log_ctx, AV_LOG_ERROR,
                "Invalid non-positive values for shape size %dx%d\n", cols, rows);
-        return AVERROR(EINVAL);
+        ret = AVERROR(EINVAL);
+        goto out;
     }
 
     if (anchor_x < 0 || anchor_y < 0 || anchor_x >= cols || anchor_y >= rows) {
         av_log(log_ctx, AV_LOG_ERROR,
                "Shape anchor %dx%d is not inside the rectangle with size %dx%d.\n",
                anchor_x, anchor_y, cols, rows);
-        return AVERROR(EINVAL);
+        ret = AVERROR(EINVAL);
+        goto out;
     }
 
     *kernel = cvCreateStructuringElementEx(cols, rows, anchor_x, anchor_y, shape, values);
-    av_freep(&values);
-    if (!*kernel)
-        return AVERROR(ENOMEM);
+    if (!*kernel) {
+        ret = AVERROR(ENOMEM);
+        goto out;
+    }
 
     av_log(log_ctx, AV_LOG_VERBOSE, "Structuring element: w:%d h:%d x:%d y:%d shape:%s\n",
            rows, cols, anchor_x, anchor_y, shape_str);
-    return 0;
+out:
+    av_freep(&values);
+    return ret;
 }
 
 typedef struct DilateContext {



More information about the ffmpeg-cvslog mailing list