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. ]
This commit is contained in:
jb 1999-08-20 12:17:09 +00:00
parent f4dcf8f141
commit e9a19a6ecd
3 changed files with 69 additions and 18 deletions

View File

@ -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 <errno.h>
#include <string.h>
@ -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);

View File

@ -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 <errno.h>
#include <string.h>
@ -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);

View File

@ -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 <errno.h>
#include <string.h>
@ -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);