From 2af5f6cdc19f73ffbc5d8cb89b2dc7a694d2f36f Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Fri, 23 Apr 2021 21:39:54 +0800 Subject: [PATCH] Return the error from pthread_mutex_lock in lock_thread since it's possible to fail to hold the mutex in the RTOS environment Signed-off-by: Xiang Xiao Change-Id: Ie0840679b40c4dff2177ea77af2554f9b963ce99 --- user_malloc.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/user_malloc.c b/user_malloc.c index 1895453..36258e2 100644 --- a/user_malloc.c +++ b/user_malloc.c @@ -189,14 +189,16 @@ static THREAD_MUTEX_T dmalloc_mutex; /* * mutex lock the malloc library */ -static void lock_thread(void) +static int lock_thread(void) { /* we only lock if the lock-on counter has reached 0 */ if (thread_lock_c == 0) { #if HAVE_PTHREAD_MUTEX_LOCK - pthread_mutex_lock(&dmalloc_mutex); + return pthread_mutex_lock(&dmalloc_mutex) == 0; #endif } + + return 1; } /* @@ -483,7 +485,9 @@ static int dmalloc_in(const char *file, const int line, } #if LOCK_THREADS - lock_thread(); + if (! lock_thread()) { + return 0; + } #endif if (in_alloc_b) {