From 422c839ae2d40a0a14a72418091e9e303c708192 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Tue, 23 May 2017 21:21:21 +0200 Subject: [PATCH] Fix semaphore segfault when tryWait'ing on invalid semaphore. --- lib/shared_memory.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/shared_memory.cpp b/lib/shared_memory.cpp index 0f93d803..24421402 100644 --- a/lib/shared_memory.cpp +++ b/lib/shared_memory.cpp @@ -222,6 +222,7 @@ namespace IPC { ///\brief Tries to wait for the semaphore, returns true if successful, false otherwise bool semaphore::tryWait() { + if (!(*this)){return false;} int result; #if defined(__CYGWIN__) || defined(_WIN32) result = WaitForSingleObject(mySem, 0);//wait at most 1ms @@ -237,6 +238,7 @@ namespace IPC { ///\brief Tries to wait for the semaphore for a single second, returns true if successful, false otherwise bool semaphore::tryWaitOneSecond() { + if (!(*this)){return false;} int result; #if defined(__CYGWIN__) || defined(_WIN32) result = WaitForSingleObject(mySem, 1000);//wait at most 1s