libmicrohttpd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libmicrohttpd] [PATCH] daemon: don't access thread if pthread_creat


From: Christian Grothoff
Subject: Re: [libmicrohttpd] [PATCH] daemon: don't access thread if pthread_create failed
Date: Tue, 15 Mar 2016 21:53:28 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.5.0

Committed as suggested as SVN 36932. -Christian

On 03/15/2016 08:45 PM, Dan Dedrick wrote:
> 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);
> 

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]