Match libpthread's behavior and make pthread_join(NULL, whatever) fail
authorguenther <guenther@openbsd.org>
Thu, 14 Aug 2008 05:57:06 +0000 (05:57 +0000)
committerguenther <guenther@openbsd.org>
Thu, 14 Aug 2008 05:57:06 +0000 (05:57 +0000)
instead of crashing

ok kurt@
first observed by Jung <moorang at gmail.com>

lib/librthread/rthread.c

index decb31e..da0a756 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: rthread.c,v 1.37 2008/08/14 05:20:44 guenther Exp $ */
+/*     $OpenBSD: rthread.c,v 1.38 2008/08/14 05:57:06 guenther Exp $ */
 /*
  * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org>
  * All Rights Reserved.
@@ -231,7 +231,9 @@ pthread_join(pthread_t thread, void **retval)
 {
        int e;
 
-       if (thread->tid == getthrid())
+       if (thread == NULL)
+               e = EINVAL;
+       else if (thread->tid == getthrid())
                e = EDEADLK;
        else if (thread->flags & THREAD_DETACHED)
                e = EINVAL;