From 024172be698e329e76c95e32c29ca5023fc036ac Mon Sep 17 00:00:00 2001 From: rpj Date: Wed, 18 Jul 2001 07:15:50 +0000 Subject: * mutex.c (pthread_mutexattr_init): Return ENOMEM immediately and don't dereference the NULL pointer if calloc fails. - "Scott McCaskill" --- ChangeLog | 7 +++++++ mutex.c | 23 ++++++++++------------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5061a51..4786fb2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2001-07-18 Ross Johnson + + * mutex.c (pthread_mutexattr_init): Return ENOMEM + immediately and don't dereference the NULL pointer + if calloc fails. + - "Scott McCaskill" + 2001-07-10 Ross Johnson * barrier.c: Still more revamping. The exclusive access diff --git a/mutex.c b/mutex.c index 09dbc2f..f32cf18 100644 --- a/mutex.c +++ b/mutex.c @@ -277,8 +277,8 @@ pthread_mutexattr_init (pthread_mutexattr_t * attr) * ------------------------------------------------------ */ { - pthread_mutexattr_t ma; int result = 0; + pthread_mutexattr_t ma; ma = (pthread_mutexattr_t) calloc (1, sizeof (*ma)); @@ -286,14 +286,15 @@ pthread_mutexattr_init (pthread_mutexattr_t * attr) { result = ENOMEM; } + else + { + ma->pshared = PTHREAD_PROCESS_PRIVATE; + ma->kind = PTHREAD_MUTEX_DEFAULT; - ma->pshared = PTHREAD_PROCESS_PRIVATE; - ma->kind = PTHREAD_MUTEX_DEFAULT; - - *attr = ma; - - return (result); + *attr = ma; + } + return(result); } /* pthread_mutexattr_init */ @@ -336,12 +337,9 @@ pthread_mutexattr_destroy (pthread_mutexattr_t * attr) *attr = NULL; free (ma); - - result = 0; } - return (result); - + return(result); } /* pthread_mutexattr_destroy */ @@ -386,13 +384,12 @@ pthread_mutexattr_getpshared (const pthread_mutexattr_t * attr, * ------------------------------------------------------ */ { - int result; + int result = 0; if ((attr != NULL && *attr != NULL) && (pshared != NULL)) { *pshared = (*attr)->pshared; - result = 0; } else { -- cgit v1.2.3