Do not delete the mutex, while it is being locked by other thread.
---
 src/base/os_defs.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/base/os_defs.c b/src/base/os_defs.c
index 83458c208..6c45eda0d 100644
--- a/src/base/os_defs.c
+++ b/src/base/os_defs.c
@@ -428,8 +428,14 @@ unsigned int ncs_os_lock(NCS_OS_LOCK *lock, 
NCS_OS_LOCK_REQUEST request,
                break;
        }
        case NCS_OS_LOCK_RELEASE:
-               if (pthread_mutex_destroy(&lock->lock) != 0)
-                       return (NCSCC_RC_FAILURE);
+               /* Before destroying make sure not locked by any other thread */
+               if (pthread_mutex_trylock(&lock->lock) == 0) {
+                       pthread_mutex_unlock(&lock->lock);
+                       if (pthread_mutex_destroy(&lock->lock) != 0)
+                               return (NCSCC_RC_FAILURE);
+               } else {
+                       return NCSCC_RC_FAILURE;
+               }
                break;
 
        case NCS_OS_LOCK_LOCK:
-- 
2.17.1



_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to