]> git.sesse.net Git - ffmpeg/commitdiff
dnn/dnn_backend_native_layer_conv2d: Join two arrays, avoid allocation
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Wed, 10 Mar 2021 15:21:13 +0000 (16:21 +0100)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Thu, 11 Mar 2021 11:45:45 +0000 (12:45 +0100)
Fixes Coverity issue #1473507.

Reviewed-by: Guo, Yejun <yejun.guo@intel.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavfilter/dnn/dnn_backend_native_layer_conv2d.c

index 2b83896da993dad4cbef706cd26c39b9a1c88e02..2e5aacdc2b3afcadaaa1facf023d758ab3b922b3 100644 (file)
@@ -38,6 +38,9 @@ typedef struct ThreadCommonParam{
 typedef struct ThreadParam{
     ThreadCommonParam *thread_common_param;
     int thread_start, thread_end;
+#if HAVE_PTHREAD_CANCEL
+    pthread_t thread;
+#endif
 } ThreadParam;
 
 int ff_dnn_load_layer_conv2d(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num)
@@ -187,7 +190,6 @@ 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);
 #if HAVE_PTHREAD_CANCEL
-    pthread_t *thread_id = av_malloc_array(thread_num, sizeof(*thread_id));
     int thread_stride;
 #endif
     ThreadParam **thread_param = av_malloc_array(thread_num, sizeof(*thread_param));
@@ -230,17 +232,15 @@ int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera
         thread_param[i]->thread_common_param = &thread_common_param;
         thread_param[i]->thread_start = thread_stride * i + pad_size;
         thread_param[i]->thread_end = (i == thread_num - 1) ? (height - pad_size) : (thread_param[i]->thread_start + thread_stride);
-        pthread_create(&thread_id[i], NULL, dnn_execute_layer_conv2d_thread, (void *)thread_param[i]);
+        pthread_create(&thread_param[i]->thread, NULL, dnn_execute_layer_conv2d_thread, (void *)thread_param[i]);
     }
 
     //join threads, res gets function return
     for (int i = 0; i < thread_num; i++){
-        pthread_join(thread_id[i], NULL);
+        pthread_join(thread_param[i]->thread, NULL);
     }
 
     //release memory
-    av_freep(&thread_id);
-
     for (int i = 0; i < thread_num; i++){
         av_freep(&thread_param[i]);
     }