diff mbox series

[FFmpeg-devel,20/23] dnn/dnn_backend_native_layer_conv2d: Check thread creation for errors

Message ID 20210310215446.1396386-11-andreas.rheinhardt@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,1/8] avcodec/cbs: Remove redundant checks for CodedBitstreamContext.codec | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt March 10, 2021, 9:54 p.m. UTC
Fixes Coverity issue #1473533.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavfilter/dnn/dnn_backend_native_layer_conv2d.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

Comments

Guo, Yejun March 11, 2021, 7:39 a.m. UTC | #1
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Andreas Rheinhardt
> Sent: 2021年3月11日 5:55
> To: ffmpeg-devel@ffmpeg.org
> Cc: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> Subject: [FFmpeg-devel] [PATCH 20/23]
> dnn/dnn_backend_native_layer_conv2d: Check thread creation for errors
> 
> Fixes Coverity issue #1473533.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavfilter/dnn/dnn_backend_native_layer_conv2d.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c
> b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c
> index 941330c895..44e5bdb5f7 100644
> --- a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c
> +++ b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c
> @@ -190,7 +190,7 @@ int ff_dnn_execute_layer_conv2d(DnnOperand
> *operands, const int32_t *input_opera  #if HAVE_PTHREAD_CANCEL
>      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;
> +    int ret = DNN_SUCCESS, thread_stride;
>      ThreadParam *thread_param;
>  #else
>      ThreadParam thread_param = { 0 };
> @@ -236,7 +236,12 @@ 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_param[i].thread, NULL,
> dnn_execute_layer_conv2d_thread, &thread_param[i]);
> +        if (pthread_create(&thread_param[i].thread, NULL,
> +                           dnn_execute_layer_conv2d_thread,
> &thread_param[i])) {
> +            thread_num = i;
> +            ret = DNN_ERROR;
> +            break;
> +        }
>      }
> 
>      //join threads, res gets function return @@ -246,12 +251,14 @@ int
> ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t
> *input_opera
> 
>      //release memory
>      av_free(thread_param);
> +
> +    return ret;
>  #else
>      thread_param.thread_common_param = &thread_common_param;
>      thread_param.thread_start = pad_size;
>      thread_param.thread_end = height - pad_size;
>      dnn_execute_layer_conv2d_thread(&thread_param);
> -#endif
> 
>      return DNN_SUCCESS;
> +#endif
>  }
> --
LGTM, thanks.
diff mbox series

Patch

diff --git a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c
index 941330c895..44e5bdb5f7 100644
--- a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c
+++ b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c
@@ -190,7 +190,7 @@  int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera
 #if HAVE_PTHREAD_CANCEL
     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;
+    int ret = DNN_SUCCESS, thread_stride;
     ThreadParam *thread_param;
 #else
     ThreadParam thread_param = { 0 };
@@ -236,7 +236,12 @@  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_param[i].thread, NULL, dnn_execute_layer_conv2d_thread, &thread_param[i]);
+        if (pthread_create(&thread_param[i].thread, NULL,
+                           dnn_execute_layer_conv2d_thread, &thread_param[i])) {
+            thread_num = i;
+            ret = DNN_ERROR;
+            break;
+        }
     }
 
     //join threads, res gets function return
@@ -246,12 +251,14 @@  int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera
 
     //release memory
     av_free(thread_param);
+
+    return ret;
 #else
     thread_param.thread_common_param = &thread_common_param;
     thread_param.thread_start = pad_size;
     thread_param.thread_end = height - pad_size;
     dnn_execute_layer_conv2d_thread(&thread_param);
-#endif
 
     return DNN_SUCCESS;
+#endif
 }