Fix bug for invalid access variable.
authorKIM JungYong <jyong2.kim@samsung.com>
Wed, 5 Oct 2016 11:55:36 +0000 (20:55 +0900)
committerUze Choi <uzchoi@samsung.com>
Mon, 10 Oct 2016 02:05:50 +0000 (02:05 +0000)
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 <jyong2.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/12815
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
(cherry picked from commit 7c6e61367021005ed0fdc401513629eb6fb48d07)
Reviewed-on: https://gerrit.iotivity.org/gerrit/12899

service/notification/src/consumer/NSThread.c

index 8490acd..ea5ce00 100644 (file)
@@ -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));