Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / service / soft-sensor-manager / SSMCore / src / QueryProcessor / QueryEngine.cpp
index 7399891..4392b8f 100644 (file)
@@ -137,13 +137,14 @@ SSMRESULT CQueryEngine::processQueryResult(int userTriggerId,
 
         for (unsigned int j = 0; j < (result_model_data_id)[i].dataId.size(); j++)
         {
-            CModelData *pModelData = new CModelData();
+            CModelData *pModelData = NULL;
             IContextModel       *pCM = NULL;
             ModelPropertyVec    modelPropertyVec;
 
             SSM_CLEANUP_ASSERT(m_pPropagationEngine->getContextModel((result_model_data_id)[i].modelName,
                                &pCM));
             SSM_CLEANUP_ASSERT(pCM->getModelData((result_model_data_id)[i].dataId[j], &modelPropertyVec));
+            pModelData = new CModelData();
             pModelData->setDataId((result_model_data_id)[i].dataId[j]);
             for (ModelPropertyVec::iterator itor = modelPropertyVec.begin();
                  itor != modelPropertyVec.end(); ++itor)
@@ -162,6 +163,7 @@ SSMRESULT CQueryEngine::processQueryResult(int userTriggerId,
     pData[0] = EVENT_TYPE_OUTER;
     pData[1] = userTriggerId;
     pData[2] = reinterpret_cast<intptr_t>(pDataReader);
+    pDataReader = NULL;
 
     m_pTasker->addTask(this, (void *)pData);
 
@@ -169,6 +171,7 @@ SSMRESULT CQueryEngine::processQueryResult(int userTriggerId,
 
 CLEANUP:
     m_mtxQueries.unlock();
+    SAFE_DELETE(pDataReader);
     SAFE_RELEASE(temp_contextmodel);
     SAFE_RELEASE(temp_contextmodel2);
     return res;
@@ -318,6 +321,7 @@ SSMRESULT CQueryEngine::executeContextQuery(std::string contextQuery, int *cqid)
     pConditionedQuery->addRef();
     m_conditionedQueries[m_cqid] = pConditionedQuery;
     m_contextQueries[m_cqid] = clsContextQuery;
+    clsContextQuery = NULL; //Mark it NULL, so that it's not freed in CLEANUP.
     m_mtxQueries.unlock();
 
     if (pConditionedQuery->hasAllConditionedModels() == true)
@@ -366,6 +370,7 @@ SSMRESULT CQueryEngine::executeContextQuery(std::string contextQuery, int *cqid)
 CLEANUP:
     SAFE_RELEASE(pConditionedQuery);
     SAFE_RELEASE(pConditionedQueryResult);
+    SAFE_DELETE(clsContextQuery);
     return res;
 }