From a02b93bd75a9d156117264d88069566e447397e2 Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Mon, 28 Jun 2010 14:20:22 -0700 Subject: [PATCH] libc: add sanity checks to pthread_mutex_destroy() Change-Id: Iddb2204fa792fa9aca5f19838926dddbb09b74a2 --- libc/bionic/pthread.c | 9 +++++++-- libc/docs/CHANGES.TXT | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/libc/bionic/pthread.c b/libc/bionic/pthread.c index 061cce1e8..e21a1f9a7 100644 --- a/libc/bionic/pthread.c +++ b/libc/bionic/pthread.c @@ -880,8 +880,13 @@ int pthread_mutex_init(pthread_mutex_t *mutex, int pthread_mutex_destroy(pthread_mutex_t *mutex) { - if (__unlikely(mutex == NULL)) - return EINVAL; + int ret; + + /* use trylock to ensure that the mutex value is + * valid and is not already locked. */ + ret = pthread_mutex_trylock(mutex); + if (ret != 0) + return ret; mutex->value = 0xdead10cc; return 0; diff --git a/libc/docs/CHANGES.TXT b/libc/docs/CHANGES.TXT index 83703d819..5a7a1ac90 100644 --- a/libc/docs/CHANGES.TXT +++ b/libc/docs/CHANGES.TXT @@ -3,7 +3,9 @@ Bionic ChangeLog: Differences between current and Android 2.2: -- : Add reader/writer locks implementation. +- : Add reader/writer locks implementation. Add sanity + checking to pthread_mutex_destroy() (e.g. a locked mutex will return + EBUSY). - : Use private futexes for semaphore implementation, unless your set 'pshared' to non-0 when calling sem_init().