If pthread_create fails for some reason we need to not access the thread pointer as it will not be valid. Without this check a failed return code from pthread_create would cause a SIGSEGV to occur.
An instance that pthread_create could fail is if enough connections were established that we ran out of space in our mapping to create another thread stack. Specifically I have seen this occur with systemd-journal-gatewayd where there was a bug with not releasing connections after they had disconnected. I submitted a fix for that here: https://github.com/systemd/systemd/pull/2287 but it would really be best if libmicrohttpd didn't SIGSEGV under these conditions. --- src/microhttpd/daemon.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index 1478604..e4d4e91 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c @@ -1283,7 +1283,8 @@ create_thread (MHD_thread_handle_ *thread, ret = pthread_create (thread, pattr, start_routine, arg); #ifdef HAVE_PTHREAD_SETNAME_NP - (void) pthread_setname_np (*thread, "libmicrohttpd"); + if (0 == ret) + (void) pthread_setname_np (*thread, "libmicrohttpd"); #endif /* HAVE_PTHREAD_SETNAME_NP */ if (0 != daemon->thread_stack_size) pthread_attr_destroy (&attr); -- 2.4.3
