[FFmpeg-cvslog] dnn/dnn_backend_native_layer_conv2d: Fix memleak on error

Andreas Rheinhardt git at videolan.org
Thu Mar 11 15:05:02 EET 2021


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Wed Mar 10 17:22:29 2021 +0100| [508d7005a00ea0d047834d661109c57a1bacef53] | committer: Andreas Rheinhardt

dnn/dnn_backend_native_layer_conv2d: Fix memleak on error

If an error happens when preparing the output data buffer, an already
allocated array would leak. Fix this by postponing its allocation.

Fixes Coverity issue #1473531.

Reviewed-by: Guo, Yejun <yejun.guo at intel.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>

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

 libavfilter/dnn/dnn_backend_native_layer_conv2d.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c
index 61e5628843..1306ae42fc 100644
--- a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c
+++ b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c
@@ -191,7 +191,7 @@ int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera
     int thread_num = (ctx->options.conv2d_threads <= 0 || ctx->options.conv2d_threads > av_cpu_count())
         ? (av_cpu_count() + 1) : (ctx->options.conv2d_threads);
     int thread_stride;
-    ThreadParam **thread_param = av_malloc_array(thread_num, sizeof(*thread_param));
+    ThreadParam **thread_param;
 #else
     ThreadParam thread_param = { 0 };
 #endif
@@ -227,6 +227,7 @@ int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera
     thread_common_param.ctx = ctx;
 
 #if HAVE_PTHREAD_CANCEL
+    thread_param = av_malloc_array(thread_num, sizeof(*thread_param));
     thread_stride = (height - pad_size * 2) / thread_num;
     //create threads
     for (int i = 0; i < thread_num; i++){



More information about the ffmpeg-cvslog mailing list