From 59208fd9c6a921c955c3f126e3cbd0ef2d37d76f Mon Sep 17 00:00:00 2001 From: Marcello Seri Date: Tue, 24 Jan 2017 16:42:42 +0000 Subject: [PATCH] Fix with_acquire: release a non locked mutex is UB This is segfaulting (on ubuntu 16.04 and 16.10) when trying to release the unlocked mutex in the release stage (in general this is an undefined behavior). --- src/threads/CCSemaphore.ml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/threads/CCSemaphore.ml b/src/threads/CCSemaphore.ml index 17d0b6de..b67408a0 100644 --- a/src/threads/CCSemaphore.ml +++ b/src/threads/CCSemaphore.ml @@ -53,14 +53,13 @@ let release m t = *) let with_acquire ~n t ~f = - Mutex.lock t.mutex; - acquire_once_locked_ n t; + acquire n t; try let x = f() in - release_once_locked_ n t; + release n t; x with e -> - release_once_locked_ n t; + release n t; raise e (*$R