From d4438b14ccd37931c12e6101ba61b00d14f0c21b Mon Sep 17 00:00:00 2001 From: Phillip Adair Stewart Whelan Date: Thu, 26 Sep 2024 12:51:56 -0300 Subject: [PATCH] lib: execute pthread_join only when tid != 0 in flb_stop (backport #9428). Signed-off-by: Phillip Adair Stewart Whelan --- src/flb_lib.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/flb_lib.c b/src/flb_lib.c index 1821a2e61ad..c8e6bd7648e 100644 --- a/src/flb_lib.c +++ b/src/flb_lib.c @@ -792,11 +792,17 @@ int flb_stop(flb_ctx_t *ctx) * There is a chance the worker thread is still active while * the service exited for some reason (plugin action). Always * wait and double check that the child thread is not running. + * + * We check the value of tid first to avoid crashes on some + * linux distributions. */ + + if (tid != 0) { #if defined(FLB_SYSTEM_MACOS) - pthread_cancel(tid); + pthread_cancel(tid); #endif - pthread_join(tid, NULL); + pthread_join(tid, NULL); + } return 0; }