diff options
author | rpj <rpj> | 2001-07-18 07:15:50 +0000 |
---|---|---|
committer | rpj <rpj> | 2001-07-18 07:15:50 +0000 |
commit | 024172be698e329e76c95e32c29ca5023fc036ac (patch) | |
tree | 4d895e08afa73962e74b57aee86343e9898bceed | |
parent | a6b214d1eb218ec6a9d78abeaa483fbf6f485aad (diff) |
* mutex.c (pthread_mutexattr_init): Return ENOMEM
immediately and don't dereference the NULL pointer
if calloc fails.
- "Scott McCaskill" <scott@magruder.org>
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | mutex.c | 23 |
2 files changed, 17 insertions, 13 deletions
@@ -1,3 +1,10 @@ +2001-07-18 Ross Johnson <rpj@setup1.ise.canberra.edu.au>
+
+ * mutex.c (pthread_mutexattr_init): Return ENOMEM
+ immediately and don't dereference the NULL pointer
+ if calloc fails.
+ - "Scott McCaskill" <scott@magruder.org>
+
2001-07-10 Ross Johnson <rpj@setup1.ise.canberra.edu.au>
* barrier.c: Still more revamping. The exclusive access
@@ -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 { |