[FFmpeg-devel] [PATCH V2] vf_hwupload: Add missing return value check

Jun Zhao mypopydev at gmail.com
Fri Mar 3 03:35:29 EET 2017


V2: Fix the potential memory leak.2
-------------- next part --------------
From eb283d277679b5dac9c43e8d3c98bcc9367b592f Mon Sep 17 00:00:00 2001
From: Jun Zhao <jun.zhao at intel.com>
Date: Fri, 3 Mar 2017 09:25:53 +0800
Subject: [PATCH] vf_hwupload: Add missing return value check

Add missing return value checks and fix the potential memory leak.

Signed-off-by: Jun Zhao <jun.zhao at intel.com>
---
 libavfilter/vf_hwupload.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/libavfilter/vf_hwupload.c b/libavfilter/vf_hwupload.c
index 08af2dd..4b63a2a 100644
--- a/libavfilter/vf_hwupload.c
+++ b/libavfilter/vf_hwupload.c
@@ -74,22 +74,28 @@ static int hwupload_query_formats(AVFilterContext *avctx)
     if (input_pix_fmts) {
         for (i = 0; input_pix_fmts[i] != AV_PIX_FMT_NONE; i++) {
             err = ff_add_format(&input_formats, input_pix_fmts[i]);
-            if (err < 0) {
-                ff_formats_unref(&input_formats);
+            if (err < 0)
                 goto fail;
-            }
         }
     }
 
-    ff_formats_ref(input_formats, &avctx->inputs[0]->out_formats);
+    if ((err = ff_formats_ref(input_formats, &avctx->inputs[0]->out_formats)) < 0)
+        goto fail;
 
-    ff_formats_ref(ff_make_format_list(output_pix_fmts),
-                   &avctx->outputs[0]->in_formats);
+    if ((err = ff_formats_ref(ff_make_format_list(output_pix_fmts),
+                              &avctx->outputs[0]->in_formats)) < 0) {
+        ff_formats_unref(&input_formats);
+        goto fail;
+    }
 
     av_hwframe_constraints_free(&constraints);
     return 0;
 
 fail:
+    if (input_formats) {
+        av_free(input_formats->formats);
+        av_free(input_formats);
+    }
     av_buffer_unref(&ctx->hwdevice_ref);
     av_hwframe_constraints_free(&constraints);
     return err;
-- 
2.9.3



More information about the ffmpeg-devel mailing list