[FFmpeg-cvslog] lavfi/dnn_backend_openvino.c: fix mem leak for AVFrame upon error

Guo, Yejun git at videolan.org
Thu Mar 18 03:55:56 EET 2021


ffmpeg | branch: master | Guo, Yejun <yejun.guo at intel.com> | Sat Mar 13 13:35:29 2021 +0800| [3ce2ee7f54ccbb20c88c1e8e0cc5796e06580ad0] | committer: Guo, Yejun

lavfi/dnn_backend_openvino.c: fix mem leak for AVFrame upon error

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

 libavfilter/dnn/dnn_backend_openvino.c | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/libavfilter/dnn/dnn_backend_openvino.c b/libavfilter/dnn/dnn_backend_openvino.c
index 5be053b7f8..d86fb124d5 100644
--- a/libavfilter/dnn/dnn_backend_openvino.c
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -485,25 +485,12 @@ static DNNReturnType get_output_ov(void *model, const char *input_name, int inpu
     OVContext *ctx = &ov_model->ctx;
     TaskItem task;
     RequestItem request;
-    AVFrame *in_frame = av_frame_alloc();
+    AVFrame *in_frame = NULL;
     AVFrame *out_frame = NULL;
     TaskItem *ptask = &task;
     IEStatusCode status;
     input_shapes_t input_shapes;
 
-    if (!in_frame) {
-        av_log(ctx, AV_LOG_ERROR, "Failed to allocate memory for input frame\n");
-        return DNN_ERROR;
-    }
-    out_frame = av_frame_alloc();
-    if (!out_frame) {
-        av_log(ctx, AV_LOG_ERROR, "Failed to allocate memory for output frame\n");
-        av_frame_free(&in_frame);
-        return DNN_ERROR;
-    }
-    in_frame->width = input_width;
-    in_frame->height = input_height;
-
     if (ctx->options.input_resizable) {
         status = ie_network_get_input_shapes(ov_model->network, &input_shapes);
         input_shapes.shapes->shape.dims[2] = input_height;
@@ -523,6 +510,21 @@ static DNNReturnType get_output_ov(void *model, const char *input_name, int inpu
         }
     }
 
+    in_frame = av_frame_alloc();
+    if (!in_frame) {
+        av_log(ctx, AV_LOG_ERROR, "Failed to allocate memory for input frame\n");
+        return DNN_ERROR;
+    }
+    in_frame->width = input_width;
+    in_frame->height = input_height;
+
+    out_frame = av_frame_alloc();
+    if (!out_frame) {
+        av_log(ctx, AV_LOG_ERROR, "Failed to allocate memory for output frame\n");
+        av_frame_free(&in_frame);
+        return DNN_ERROR;
+    }
+
     task.done = 0;
     task.do_ioproc = 0;
     task.async = 0;



More information about the ffmpeg-cvslog mailing list