From fcfcff954d697fcfe03804a3acc7d83006d6ae45 Mon Sep 17 00:00:00 2001 From: Johannes Nixdorf Date: Sat, 3 Apr 2021 12:02:40 +0200 Subject: [PATCH] Request a reasonably small thread stack This somewhat mitigates the problem that now the buffer is allocated in addition to the already allocated thread stack. --- fiche.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fiche.c b/fiche.c index 370dbac..d4a4bfa 100644 --- a/fiche.c +++ b/fiche.c @@ -33,6 +33,7 @@ Use netcat to push text - example: #include #include +#include #include #include #include @@ -520,12 +521,18 @@ static void dispatch_connection(int socket, Fiche_Settings *settings) { // Spawn a new thread to handle this connection pthread_t id; + pthread_attr_t attr; - if ( pthread_create(&id, NULL, &handle_connection, c) != 0 ) { + if ( (errno = pthread_attr_init(&attr)) || + (errno = pthread_attr_setstacksize(&attr, 16*1024)) || + (errno = pthread_create(&id, &attr, &handle_connection, c)) ) { + pthread_attr_destroy(&attr); print_error("Couldn't spawn a thread!"); return; } + pthread_attr_destroy(&attr); + // Detach thread if created succesfully // TODO: consider using pthread_tryjoin_np pthread_detach(id);