summaryrefslogtreecommitdiff
path: root/mutex.c
diff options
context:
space:
mode:
authorrpj <rpj>2001-07-18 07:15:50 +0000
committerrpj <rpj>2001-07-18 07:15:50 +0000
commit024172be698e329e76c95e32c29ca5023fc036ac (patch)
tree4d895e08afa73962e74b57aee86343e9898bceed /mutex.c
parenta6b214d1eb218ec6a9d78abeaa483fbf6f485aad (diff)
* mutex.c (pthread_mutexattr_init): Return ENOMEM
immediately and don't dereference the NULL pointer if calloc fails. - "Scott McCaskill" <scott@magruder.org>
Diffstat (limited to 'mutex.c')
-rw-r--r--mutex.c23
1 files changed, 10 insertions, 13 deletions
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
{