am 7d1d98b9: am a02b93bd: libc: add sanity checks to pthread_mutex_destroy()
Merge commit '7d1d98b97e947de22aff4c0b67eec7ae68c822ee'
* commit '7d1d98b97e947de22aff4c0b67eec7ae68c822ee':
libc: add sanity checks to pthread_mutex_destroy()
diff --git a/libc/bionic/pthread.c b/libc/bionic/pthread.c
index a60da27..b28cd9f 100644
--- a/libc/bionic/pthread.c
+++ b/libc/bionic/pthread.c
@@ -880,8 +880,13 @@
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 02526e2..5e0c1bd 100644
--- a/libc/docs/CHANGES.TXT
+++ b/libc/docs/CHANGES.TXT
@@ -3,7 +3,9 @@
Differences between current and Android 2.2:
-- <pthread.h>: Add reader/writer locks implementation.
+- <pthread.h>: Add reader/writer locks implementation. Add sanity
+ checking to pthread_mutex_destroy() (e.g. a locked mutex will return
+ EBUSY).
- <math.h>: Added sincos(), sincosf() and sincosl() (GLibc compatibility).