Skip to content

Commit

Permalink
musl thread fix (#1)
Browse files Browse the repository at this point in the history
* Deduplicate the cleanup in handle_connection()

* Remove the VLA from handle_connection()

This fixes a segfault on musl libc with reasonable sized buffers, as
musl's default thread stack size is quite small (128k since 1.1.21).

A similar bug exists on glibc with large enough buffers (reproducable
with e.g. 16MB on my test system).

This commit fixes solusipse#108.

* Remove the superfluous call to pthread_exit

Returning from the start function of a thread is specified to
implicitly call pthread_exit().

* 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.

Co-authored-by: Johannes Nixdorf <[email protected]>
  • Loading branch information
drscream and mixi committed Oct 19, 2021
1 parent 3a8b691 commit 1331508
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fiche.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,8 @@ static void dispatch_connection(int socket, Fiche_Settings *settings) {
pthread_attr_destroy(&attr);

// Detach thread if created successfully
pthread_attr_destroy(&attr);

// TODO: consider using pthread_tryjoin_np
pthread_detach(id);

Expand Down

0 comments on commit 1331508

Please sign in to comment.