From 13ab4521652872e460cd02f651c8546b1a7bc950 Mon Sep 17 00:00:00 2001
From: eaglegai <eaglegai@163.com>
Date: Wed, 24 May 2023 18:51:35 +0800
Subject: [PATCH] add check for pthread_create

Signed-off-by: eaglegai <eaglegai@163.com>
---
 src/thread.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/thread.c b/src/thread.c
index 7318de9..a5b9ba4 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -943,10 +943,11 @@ static void *dummy_thread_function(void *data)
 	return NULL;
 }
 
-static inline void preload_libgcc_s(void)
+static inline int preload_libgcc_s(void)
 {
 	pthread_t dummy_thread;
-	pthread_create(&dummy_thread, NULL, dummy_thread_function, NULL);
+	if(pthread_create(&dummy_thread, NULL, dummy_thread_function, NULL) != 0)
+		return -1;
 	pthread_join(dummy_thread, NULL);
 }
 
@@ -961,7 +962,10 @@ static void __thread_init(void)
 		exit(1);
 	}
 
-	preload_libgcc_s();
+	if (preload_libgcc_s() < 0) {
+		ha_alert("pthread create failed");
+		exit(1);
+	}
 
 	thread_cpus_enabled_at_boot = thread_cpus_enabled();
 
-- 
2.33.0

