From c6637d28b3ca72411273a6044b5ac622089d3bf3 Mon Sep 17 00:00:00 2001 From: jb Date: Fri, 20 Aug 1999 12:17:09 +0000 Subject: [PATCH] When checking if there is a stack to free, observe the fact that it might have been mmapped, and if so, passing the pointer to free() is really not a good idea. [ In the next millenium, when I've taken over the world, I'm going to ban 8 character tabs. You've been warned. ] --- lib/libc_r/uthread/uthread_fork.c | 29 +++++++++++++++++++++++------ lib/libkse/thread/thr_fork.c | 29 +++++++++++++++++++++++------ lib/libpthread/thread/thr_fork.c | 29 +++++++++++++++++++++++------ 3 files changed, 69 insertions(+), 18 deletions(-) diff --git a/lib/libc_r/uthread/uthread_fork.c b/lib/libc_r/uthread/uthread_fork.c index 8ef8a3c9ce8d..f2e352c210dd 100644 --- a/lib/libc_r/uthread/uthread_fork.c +++ b/lib/libc_r/uthread/uthread_fork.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_fork.c,v 1.10 1999/06/20 08:28:23 jb Exp $ + * $Id: uthread_fork.c,v 1.11 1999/08/05 12:15:11 deischen Exp $ */ #include #include @@ -131,11 +131,28 @@ fork(void) if (pthread_save->attr.stackaddr_attr == NULL && pthread_save->stack != NULL) - /* - * Free the stack of the - * dead thread: - */ - free(pthread_save->stack); + if (pthread_save->attr.stacksize_attr + == PTHREAD_STACK_DEFAULT) { + /* + * Default-size stack. Cache + * it: + */ + struct stack *spare_stack; + + spare_stack + = (pthread_save->stack + + PTHREAD_STACK_DEFAULT + - sizeof(struct stack)); + SLIST_INSERT_HEAD( + &_stackq, + spare_stack, + qe); + } else + /* + * Free the stack of + * the dead thread: + */ + free(pthread_save->stack); if (pthread_save->specific_data != NULL) free(pthread_save->specific_data); diff --git a/lib/libkse/thread/thr_fork.c b/lib/libkse/thread/thr_fork.c index 8ef8a3c9ce8d..f2e352c210dd 100644 --- a/lib/libkse/thread/thr_fork.c +++ b/lib/libkse/thread/thr_fork.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_fork.c,v 1.10 1999/06/20 08:28:23 jb Exp $ + * $Id: uthread_fork.c,v 1.11 1999/08/05 12:15:11 deischen Exp $ */ #include #include @@ -131,11 +131,28 @@ fork(void) if (pthread_save->attr.stackaddr_attr == NULL && pthread_save->stack != NULL) - /* - * Free the stack of the - * dead thread: - */ - free(pthread_save->stack); + if (pthread_save->attr.stacksize_attr + == PTHREAD_STACK_DEFAULT) { + /* + * Default-size stack. Cache + * it: + */ + struct stack *spare_stack; + + spare_stack + = (pthread_save->stack + + PTHREAD_STACK_DEFAULT + - sizeof(struct stack)); + SLIST_INSERT_HEAD( + &_stackq, + spare_stack, + qe); + } else + /* + * Free the stack of + * the dead thread: + */ + free(pthread_save->stack); if (pthread_save->specific_data != NULL) free(pthread_save->specific_data); diff --git a/lib/libpthread/thread/thr_fork.c b/lib/libpthread/thread/thr_fork.c index 8ef8a3c9ce8d..f2e352c210dd 100644 --- a/lib/libpthread/thread/thr_fork.c +++ b/lib/libpthread/thread/thr_fork.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_fork.c,v 1.10 1999/06/20 08:28:23 jb Exp $ + * $Id: uthread_fork.c,v 1.11 1999/08/05 12:15:11 deischen Exp $ */ #include #include @@ -131,11 +131,28 @@ fork(void) if (pthread_save->attr.stackaddr_attr == NULL && pthread_save->stack != NULL) - /* - * Free the stack of the - * dead thread: - */ - free(pthread_save->stack); + if (pthread_save->attr.stacksize_attr + == PTHREAD_STACK_DEFAULT) { + /* + * Default-size stack. Cache + * it: + */ + struct stack *spare_stack; + + spare_stack + = (pthread_save->stack + + PTHREAD_STACK_DEFAULT + - sizeof(struct stack)); + SLIST_INSERT_HEAD( + &_stackq, + spare_stack, + qe); + } else + /* + * Free the stack of + * the dead thread: + */ + free(pthread_save->stack); if (pthread_save->specific_data != NULL) free(pthread_save->specific_data);