From fd6098a3a27b7208411f2d9c18c005a544939dca Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sat, 16 Feb 2013 16:17:12 +0100 Subject: [PATCH] Locking a NULL pointer using ScopedLock is a noop. --- sortix/include/sortix/kernel/kthread.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sortix/include/sortix/kernel/kthread.h b/sortix/include/sortix/kernel/kthread.h index 0e62ac56..6c1ec769 100644 --- a/sortix/include/sortix/kernel/kthread.h +++ b/sortix/include/sortix/kernel/kthread.h @@ -61,12 +61,14 @@ public: ScopedLock(kthread_mutex_t* mutex) { this->mutex = mutex; - kthread_mutex_lock(mutex); + if ( mutex ) + kthread_mutex_lock(mutex); } ~ScopedLock() { - kthread_mutex_unlock(mutex); + if ( mutex ) + kthread_mutex_unlock(mutex); } private: @@ -80,12 +82,12 @@ public: ScopedLockSignal(kthread_mutex_t* mutex) { this->mutex = mutex; - this->acquired = kthread_mutex_lock_signal(mutex); + this->acquired = !mutex || kthread_mutex_lock_signal(mutex); } ~ScopedLockSignal() { - if ( acquired ) + if ( mutex && acquired ) kthread_mutex_unlock(mutex); }