libc: add sanity checks to pthread_mutex_destroy()

Change-Id: Iddb2204fa792fa9aca5f19838926dddbb09b74a2
diff --git a/libc/bionic/pthread.c b/libc/bionic/pthread.c
index 061cce1..e21a1f9 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;