diff options
author | 1999-11-30 03:16:01 +0000 | |
---|---|---|
committer | 1999-11-30 03:16:01 +0000 | |
commit | 84a89107927a01ad125ae76b695c1c1acd1d67de (patch) | |
tree | 5e663e1386c214954cee0fc062df626a4f96c7d8 /lib/libpthread | |
parent | KNF and cleanup (diff) | |
download | wireguard-openbsd-84a89107927a01ad125ae76b695c1c1acd1d67de.tar.xz wireguard-openbsd-84a89107927a01ad125ae76b695c1c1acd1d67de.zip |
really remove all other threads when fork()ing. (bug was in removing elements from a list whilest walking it)
Diffstat (limited to 'lib/libpthread')
-rw-r--r-- | lib/libpthread/uthread/uthread_fork.c | 39 |
1 files changed, 15 insertions, 24 deletions
diff --git a/lib/libpthread/uthread/uthread_fork.c b/lib/libpthread/uthread/uthread_fork.c index 0e9aef59a20..96e19ead19d 100644 --- a/lib/libpthread/uthread/uthread_fork.c +++ b/lib/libpthread/uthread/uthread_fork.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_fork.c,v 1.7 1999/11/25 07:01:35 d Exp $ */ +/* $OpenBSD: uthread_fork.c,v 1.8 1999/11/30 03:16:01 d Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -46,7 +46,6 @@ fork(void) int i, flags; pid_t ret; pthread_t pthread; - pthread_t pthread_save; /* * Defer signals to protect the scheduling queues from access @@ -113,36 +112,28 @@ fork(void) * Enter a loop to remove all threads other than * the running thread from the thread list: */ - pthread = TAILQ_FIRST(&_thread_list); - while (pthread != NULL) { - /* Save the thread to be freed: */ - pthread_save = pthread; - - /* - * Advance to the next thread before - * destroying the current thread: - */ - pthread = TAILQ_NEXT(pthread, dle); + while ((pthread = TAILQ_FIRST(&_thread_list)) != NULL) { + TAILQ_REMOVE(&_thread_list, pthread, tle); /* Make sure this isn't the running thread: */ - if (pthread_save != _thread_run) { - /* Remove this thread from the list: */ - TAILQ_REMOVE(&_thread_list, - pthread_save, tle); - - if(pthread_save->stack != NULL) - _thread_stack_free(pthread_save->stack); + if (pthread != _thread_run) { + /* XXX should let gc do all this. */ + if(pthread->stack != NULL) + _thread_stack_free(pthread->stack); - if (pthread_save->specific_data != NULL) - free(pthread_save->specific_data); + if (pthread->specific_data != NULL) + free(pthread->specific_data); - if (pthread_save->poll_data.fds != NULL) - free(pthread_save->poll_data.fds); + if (pthread->poll_data.fds != NULL) + free(pthread->poll_data.fds); - free(pthread_save); + free(pthread); } } + /* Restore the running thread */ + TAILQ_INSERT_HEAD(&_thread_list, _thread_run, tle); + /* Re-init the dead thread list: */ TAILQ_INIT(&_dead_list); |