fix unsynchronized decrement of thread count on pthread_create error
authorRich Felker <dalias@aerifal.cx>
Fri, 6 Sep 2019 19:52:00 +0000 (15:52 -0400)
committerRich Felker <dalias@aerifal.cx>
Fri, 6 Sep 2019 19:54:32 +0000 (15:54 -0400)
commit 8f11e6127fe93093f81a52b15bb1537edc3fc8af wrongly documented
that all changes to libc.threads_minus_1 were guarded by the thread
list lock, but the decrement for failed SYS_clone took place after the
thread list lock was released.

src/thread/pthread_create.c

index ebf61de..edaf9a6 100644 (file)
@@ -356,13 +356,14 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att
                new->prev = self;
                new->next->prev = new;
                new->prev->next = new;
+       } else {
+               libc.threads_minus_1--;
        }
        __tl_unlock();
        __restore_sigs(&set);
        __release_ptc();
 
        if (ret < 0) {
-               libc.threads_minus_1--;
                if (map) __munmap(map, size);
                return EAGAIN;
        }