diff options
author | jorton <jorton@13f79535-47bb-0310-9956-ffa450edef68> | 2004-06-14 09:41:04 +0000 |
---|---|---|
committer | jorton <jorton@13f79535-47bb-0310-9956-ffa450edef68> | 2004-06-14 09:41:04 +0000 |
commit | 5976343e03a4ea4d892726ed5ba5ee601a3b79c4 (patch) | |
tree | 8ecb2b25eb4958844fe03c9771aef289671ec12d /locks | |
parent | b6993f97495e3180a4bafc29e6db2e279c4c2794 (diff) | |
download | libapr-5976343e03a4ea4d892726ed5ba5ee601a3b79c4.tar.gz |
* locks/unix/proc_mutex.c (proc_mutex_proc_pthread_cleanup): Fix
resource leak: destroy the mutex here, if it was ever initialized.
(proc_mutex_proc_pthread_create): Destroy the mutexattr object
on error paths; ensure that _cleanup destroys the mutex on error
paths iff necessary.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@65190 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'locks')
-rw-r--r-- | locks/unix/proc_mutex.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/locks/unix/proc_mutex.c b/locks/unix/proc_mutex.c index ddc581caa..abc732914 100644 --- a/locks/unix/proc_mutex.c +++ b/locks/unix/proc_mutex.c @@ -266,6 +266,15 @@ static apr_status_t proc_mutex_proc_pthread_cleanup(void *mutex_) return rv; } } + /* curr_locked is set to -1 until the mutex has been created */ + if (mutex->curr_locked != -1) { + if ((rv = pthread_mutex_destroy(mutex->pthread_interproc))) { +#ifdef PTHREAD_SETS_ERRNO + rv = errno; +#endif + return rv; + } + } if (munmap((caddr_t)mutex->pthread_interproc, sizeof(pthread_mutex_t))) { return errno; } @@ -294,6 +303,9 @@ static apr_status_t proc_mutex_proc_pthread_create(apr_proc_mutex_t *new_mutex, return errno; } close(fd); + + new_mutex->curr_locked = -1; /* until the mutex has been created */ + if ((rv = pthread_mutexattr_init(&mattr))) { #ifdef PTHREAD_SETS_ERRNO rv = errno; @@ -306,6 +318,7 @@ static apr_status_t proc_mutex_proc_pthread_create(apr_proc_mutex_t *new_mutex, rv = errno; #endif proc_mutex_proc_pthread_cleanup(new_mutex); + pthread_mutexattr_destroy(&mattr); return rv; } @@ -316,6 +329,7 @@ static apr_status_t proc_mutex_proc_pthread_create(apr_proc_mutex_t *new_mutex, rv = errno; #endif proc_mutex_proc_pthread_cleanup(new_mutex); + pthread_mutexattr_destroy(&mattr); return rv; } if ((rv = pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT))) { @@ -323,6 +337,7 @@ static apr_status_t proc_mutex_proc_pthread_create(apr_proc_mutex_t *new_mutex, rv = errno; #endif proc_mutex_proc_pthread_cleanup(new_mutex); + pthread_mutexattr_destroy(&mattr); return rv; } #endif @@ -332,9 +347,12 @@ static apr_status_t proc_mutex_proc_pthread_create(apr_proc_mutex_t *new_mutex, rv = errno; #endif proc_mutex_proc_pthread_cleanup(new_mutex); + pthread_mutexattr_destroy(&mattr); return rv; } + new_mutex->curr_locked = 0; /* mutex created now */ + if ((rv = pthread_mutexattr_destroy(&mattr))) { #ifdef PTHREAD_SETS_ERRNO rv = errno; @@ -343,7 +361,6 @@ static apr_status_t proc_mutex_proc_pthread_create(apr_proc_mutex_t *new_mutex, return rv; } - new_mutex->curr_locked = 0; apr_pool_cleanup_register(new_mutex->pool, (void *)new_mutex, apr_proc_mutex_cleanup, |