[IOT-1464] Set NULL after deleting dataQueue of queueing thread
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / caqueueingthread.c
index 9a6c56a..1542098 100644 (file)
  *
  ******************************************************************/
 
+#include "iotivity_config.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
+#endif
 
 #include "caqueueingthread.h"
 #include "oic_malloc.h"
@@ -39,7 +44,6 @@ static void CAQueueingThreadBaseRoutine(void *threadValue)
     if (NULL == thread)
     {
         OIC_LOG(ERROR, TAG, "thread data passing error!!");
-
         return;
     }
 
@@ -124,28 +128,30 @@ CAResult_t CAQueueingThreadInitialize(CAQueueingThread_t *thread, ca_thread_pool
     thread->isStop = true;
     thread->threadTask = task;
     thread->destroy = destroy;
-    if(NULL == thread->dataQueue || NULL == thread->threadMutex || NULL == thread->threadCond)
+    if (NULL == thread->dataQueue || NULL == thread->threadMutex || NULL == thread->threadCond)
+    {
         goto ERROR_MEM_FAILURE;
+    }
 
     return CA_STATUS_OK;
-    ERROR_MEM_FAILURE:
-    if(thread->dataQueue)
+
+ERROR_MEM_FAILURE:
+    if (thread->dataQueue)
     {
         u_queue_delete(thread->dataQueue);
         thread->dataQueue = NULL;
     }
-    if(thread->threadMutex)
+    if (thread->threadMutex)
     {
         ca_mutex_free(thread->threadMutex);
         thread->threadMutex = NULL;
     }
-    if(thread->threadCond)
+    if (thread->threadCond)
     {
         ca_cond_free(thread->threadCond);
         thread->threadCond = NULL;
     }
     return CA_MEMORY_ALLOC_FAILED;
-
 }
 
 CAResult_t CAQueueingThreadStart(CAQueueingThread_t *thread)
@@ -247,7 +253,7 @@ CAResult_t CAQueueingThreadDestroy(CAQueueingThread_t *thread)
         u_queue_message_t *message = u_queue_get_element(thread->dataQueue);
 
         // free
-        if(NULL != message)
+        if (NULL != message)
         {
             if (NULL != thread->destroy)
             {
@@ -263,6 +269,7 @@ CAResult_t CAQueueingThreadDestroy(CAQueueingThread_t *thread)
     }
 
     u_queue_delete(thread->dataQueue);
+    thread->dataQueue = NULL;
 
     return CA_STATUS_OK;
 }