From a6da5d7d6557fdfbb6887384b6119ef7e43f2d3f Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 2 Nov 2015 01:00:48 +0100 Subject: [PATCH] darwin: abort() if (un)locking fs mutex fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The pthread_mutex_lock() and pthread_mutex_unlock() calls logically cannot fail in uv__fs_write() but let's check the return value anyway: cosmic rays and memory corruption do happen. PR-URL: https://github.com/libuv/libuv/pull/603 Reviewed-By: Saúl Ibarra Corretgé --- src/unix/fs.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/unix/fs.c b/src/unix/fs.c index d593d2ec..3f5cd6aa 100644 --- a/src/unix/fs.c +++ b/src/unix/fs.c @@ -630,7 +630,9 @@ static ssize_t uv__fs_write(uv_fs_t* req) { */ #if defined(__APPLE__) static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; - pthread_mutex_lock(&lock); + + if (pthread_mutex_lock(&lock)) + abort(); #endif if (req->off < 0) { @@ -687,7 +689,8 @@ static ssize_t uv__fs_write(uv_fs_t* req) { done: #if defined(__APPLE__) - pthread_mutex_unlock(&lock); + if (pthread_mutex_unlock(&lock)) + abort(); #endif return r;