From 1892a028ac12be664a223c1f1427dd6e008e8d87 Mon Sep 17 00:00:00 2001 From: KIM JungYong Date: Wed, 5 Oct 2016 20:55:36 +0900 Subject: [PATCH] Fix bug for invalid access variable. when access consumer main thread but initialized, service will crash. So this patch prevent invalid access to not initialized thread handle. Change-Id: I77d86a712e0efe6bbec17780426df4a5ba98decc Signed-off-by: KIM JungYong Reviewed-on: https://gerrit.iotivity.org/gerrit/12815 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi (cherry picked from commit 7c6e61367021005ed0fdc401513629eb6fb48d07) Reviewed-on: https://gerrit.iotivity.org/gerrit/12899 --- service/notification/src/consumer/NSThread.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/service/notification/src/consumer/NSThread.c b/service/notification/src/consumer/NSThread.c index 8490acd..ea5ce00 100644 --- a/service/notification/src/consumer/NSThread.c +++ b/service/notification/src/consumer/NSThread.c @@ -65,16 +65,22 @@ NSConsumerThread * NSThreadInit(NSThreadFunc func, void * data) void NSThreadLock(NSConsumerThread * handle) { + NS_VERIFY_NOT_NULL_V(handle); + pthread_mutex_lock(&(handle->mutex)); } void NSThreadUnlock(NSConsumerThread * handle) { + NS_VERIFY_NOT_NULL_V(handle); + pthread_mutex_unlock(&(handle->mutex)); } void NSThreadStop(NSConsumerThread * handle) { + NS_VERIFY_NOT_NULL_V(handle); + handle->isStarted = false; NSThreadJoin(handle); @@ -83,6 +89,8 @@ void NSThreadStop(NSConsumerThread * handle) void NSThreadJoin(NSConsumerThread * handle) { + NS_VERIFY_NOT_NULL_V(handle); + if (handle->thread_id) { pthread_join(handle->thread_id, NULL); @@ -91,6 +99,8 @@ void NSThreadJoin(NSConsumerThread * handle) void NSDestroyThreadHandle(NSConsumerThread * handle) { + NS_VERIFY_NOT_NULL_V(handle); + pthread_mutex_destroy(&(handle->mutex)); pthread_mutexattr_destroy(&(handle->mutex_attr)); -- 2.7.4