From d0abe46d41d3c8db1772337e4160ca200b9dbcff Mon Sep 17 00:00:00 2001 From: rpj Date: Mon, 15 Oct 2001 08:47:10 +0000 Subject: * spin.c (pthread_spin_lock): PTHREAD_SPINLOCK_INITIALIZER was causing a program fault. (pthread_spin_init): Could have alloced memory without freeing under some error conditions. * mutex.c (pthread_mutex_init): Move memory allocation of mutex struct after checking for PROCESS_SHARED. --- mutex.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'mutex.c') diff --git a/mutex.c b/mutex.c index 49a1a18..be039ac 100644 --- a/mutex.c +++ b/mutex.c @@ -93,14 +93,6 @@ pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) return EINVAL; } - mx = (pthread_mutex_t) calloc(1, sizeof(*mx)); - - if (mx == NULL) - { - result = ENOMEM; - goto FAIL0; - } - if (attr != NULL && *attr != NULL && (*attr)->pshared == PTHREAD_PROCESS_SHARED @@ -118,16 +110,22 @@ pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) #error ERROR [__FILE__, line __LINE__]: Process shared mutexes are not supported yet. - #else - result = ENOSYS; - goto FAIL0; + return ENOSYS; #endif /* _POSIX_THREAD_PROCESS_SHARED */ } + mx = (pthread_mutex_t) calloc(1, sizeof(*mx)); + + if (mx == NULL) + { + result = ENOMEM; + goto FAIL0; + } + mx->lock_idx = PTW32_MUTEX_LOCK_IDX_INIT; mx->recursive_count = 0; mx->kind = (attr == NULL || *attr == NULL -- cgit v1.2.3