Fix bugs for result of dynamic analizer.
[platform/upstream/iotivity.git] / service / notification / src / consumer / NSThread.c
index ea5ce00..5610636 100644 (file)
@@ -53,11 +53,17 @@ NSConsumerThread * NSThreadInit(NSThreadFunc func, void * data)
 
     handle->isStarted = true;
 
-    pthreadResult = pthread_create(&(handle->thread_id), NULL, func,
+    pthread_attr_t attrDetached;
+    pthread_attr_init(& attrDetached);
+    pthread_attr_setdetachstate(& attrDetached, PTHREAD_CREATE_DETACHED);
+
+    pthreadResult = pthread_create(&(handle->thread_id), & attrDetached, func,
                            (data == NULL) ? (void *) handle : (void *)data);
     NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(pthreadResult == 0 ? (void *)1 : NULL,
             NULL, NSDestroyThreadHandle(handle));
 
+    pthread_attr_destroy(& attrDetached);
+
     pthread_mutex_unlock(&g_create_mutex);
 
     return handle;
@@ -93,7 +99,9 @@ void NSThreadJoin(NSConsumerThread * handle)
 
     if (handle->thread_id)
     {
-        pthread_join(handle->thread_id, NULL);
+        void * retData = NULL;
+        pthread_join(handle->thread_id, & retData);
+        NSOICFree(retData);
     }
 }
 
@@ -104,8 +112,6 @@ void NSDestroyThreadHandle(NSConsumerThread * handle)
     pthread_mutex_destroy(&(handle->mutex));
     pthread_mutexattr_destroy(&(handle->mutex_attr));
 
-    NSOICFree(handle);
-
     pthread_mutex_unlock(&g_create_mutex);
 }