Merge pull request #2649 from taosdata/bugfix/td-902
fix td-902: memory leak
This commit is contained in:
commit
1e97755d03
|
@ -5627,17 +5627,23 @@ static void freeQInfo(SQInfo *pQInfo);
|
||||||
|
|
||||||
static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList, SSqlGroupbyExpr *pGroupbyExpr, SExprInfo *pExprs,
|
static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList, SSqlGroupbyExpr *pGroupbyExpr, SExprInfo *pExprs,
|
||||||
STableGroupInfo *pTableGroupInfo, SColumnInfo* pTagCols) {
|
STableGroupInfo *pTableGroupInfo, SColumnInfo* pTagCols) {
|
||||||
SQInfo *pQInfo = (SQInfo *)calloc(1, sizeof(SQInfo));
|
|
||||||
if (pQInfo == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
SQuery *pQuery = calloc(1, sizeof(SQuery));
|
|
||||||
pQInfo->runtimeEnv.pQuery = pQuery;
|
|
||||||
|
|
||||||
int16_t numOfCols = pQueryMsg->numOfCols;
|
int16_t numOfCols = pQueryMsg->numOfCols;
|
||||||
int16_t numOfOutput = pQueryMsg->numOfOutput;
|
int16_t numOfOutput = pQueryMsg->numOfOutput;
|
||||||
|
|
||||||
|
SQInfo *pQInfo = (SQInfo *)calloc(1, sizeof(SQInfo));
|
||||||
|
if (pQInfo == NULL) {
|
||||||
|
goto _cleanup_qinfo;
|
||||||
|
}
|
||||||
|
// to make sure third party won't overwrite this structure
|
||||||
|
pQInfo->signature = pQInfo;
|
||||||
|
pQInfo->tableGroupInfo = *pTableGroupInfo;
|
||||||
|
|
||||||
|
SQuery *pQuery = calloc(1, sizeof(SQuery));
|
||||||
|
if (pQuery == NULL) {
|
||||||
|
goto _cleanup_query;
|
||||||
|
}
|
||||||
|
pQInfo->runtimeEnv.pQuery = pQuery;
|
||||||
|
|
||||||
pQuery->numOfCols = numOfCols;
|
pQuery->numOfCols = numOfCols;
|
||||||
pQuery->numOfOutput = numOfOutput;
|
pQuery->numOfOutput = numOfOutput;
|
||||||
pQuery->limit.limit = pQueryMsg->limit;
|
pQuery->limit.limit = pQueryMsg->limit;
|
||||||
|
@ -5651,6 +5657,7 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList,
|
||||||
pQuery->slidingTimeUnit = pQueryMsg->slidingTimeUnit;
|
pQuery->slidingTimeUnit = pQueryMsg->slidingTimeUnit;
|
||||||
pQuery->fillType = pQueryMsg->fillType;
|
pQuery->fillType = pQueryMsg->fillType;
|
||||||
pQuery->numOfTags = pQueryMsg->numOfTags;
|
pQuery->numOfTags = pQueryMsg->numOfTags;
|
||||||
|
pQuery->tagColList = pTagCols;
|
||||||
|
|
||||||
// todo do not allocate ??
|
// todo do not allocate ??
|
||||||
pQuery->colList = calloc(numOfCols, sizeof(SSingleColumnFilterInfo));
|
pQuery->colList = calloc(numOfCols, sizeof(SSingleColumnFilterInfo));
|
||||||
|
@ -5663,8 +5670,6 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList,
|
||||||
pQuery->colList[i].filters = tscFilterInfoClone(pQueryMsg->colList[i].filters, pQuery->colList[i].numOfFilters);
|
pQuery->colList[i].filters = tscFilterInfoClone(pQueryMsg->colList[i].filters, pQuery->colList[i].numOfFilters);
|
||||||
}
|
}
|
||||||
|
|
||||||
pQuery->tagColList = pTagCols;
|
|
||||||
|
|
||||||
// calculate the result row size
|
// calculate the result row size
|
||||||
for (int16_t col = 0; col < numOfOutput; ++col) {
|
for (int16_t col = 0; col < numOfOutput; ++col) {
|
||||||
assert(pExprs[col].bytes > 0);
|
assert(pExprs[col].bytes > 0);
|
||||||
|
@ -5709,10 +5714,6 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList,
|
||||||
memcpy(pQuery->fillVal, (char *)pQueryMsg->fillVal, pQuery->numOfOutput * sizeof(int64_t));
|
memcpy(pQuery->fillVal, (char *)pQueryMsg->fillVal, pQuery->numOfOutput * sizeof(int64_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
// to make sure third party won't overwrite this structure
|
|
||||||
pQInfo->signature = pQInfo;
|
|
||||||
|
|
||||||
pQInfo->tableGroupInfo = *pTableGroupInfo;
|
|
||||||
size_t numOfGroups = 0;
|
size_t numOfGroups = 0;
|
||||||
if (pTableGroupInfo->pGroupList != NULL) {
|
if (pTableGroupInfo->pGroupList != NULL) {
|
||||||
numOfGroups = taosArrayGetSize(pTableGroupInfo->pGroupList);
|
numOfGroups = taosArrayGetSize(pTableGroupInfo->pGroupList);
|
||||||
|
@ -5775,6 +5776,21 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList,
|
||||||
qDebug("qmsg:%p QInfo:%p created", pQueryMsg, pQInfo);
|
qDebug("qmsg:%p QInfo:%p created", pQueryMsg, pQInfo);
|
||||||
return pQInfo;
|
return pQInfo;
|
||||||
|
|
||||||
|
_cleanup_qinfo:
|
||||||
|
tsdbDestoryTableGroup(pTableGroupInfo);
|
||||||
|
|
||||||
|
_cleanup_query:
|
||||||
|
taosArrayDestroy(pGroupbyExpr->columnInfo);
|
||||||
|
tfree(pGroupbyExpr);
|
||||||
|
tfree(pTagCols);
|
||||||
|
for (int32_t i = 0; i < numOfOutput; ++i) {
|
||||||
|
SExprInfo* pExprInfo = &pExprs[i];
|
||||||
|
if (pExprInfo->pExpr != NULL) {
|
||||||
|
tExprTreeDestroy(&pExprInfo->pExpr, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tfree(pExprs);
|
||||||
|
|
||||||
_cleanup:
|
_cleanup:
|
||||||
freeQInfo(pQInfo);
|
freeQInfo(pQInfo);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -5893,6 +5909,7 @@ static void freeQInfo(SQInfo *pQInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo refactor, extract method to destroytableDataInfo
|
// todo refactor, extract method to destroytableDataInfo
|
||||||
|
if (pQInfo->tableqinfoGroupInfo.pGroupList != NULL) {
|
||||||
int32_t numOfGroups = GET_NUM_OF_TABLEGROUP(pQInfo);
|
int32_t numOfGroups = GET_NUM_OF_TABLEGROUP(pQInfo);
|
||||||
for (int32_t i = 0; i < numOfGroups; ++i) {
|
for (int32_t i = 0; i < numOfGroups; ++i) {
|
||||||
SArray *p = GET_TABLEGROUP(pQInfo, i);
|
SArray *p = GET_TABLEGROUP(pQInfo, i);
|
||||||
|
@ -5907,6 +5924,7 @@ static void freeQInfo(SQInfo *pQInfo) {
|
||||||
|
|
||||||
taosArrayDestroy(p);
|
taosArrayDestroy(p);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tfree(pQInfo->pBuf);
|
tfree(pQInfo->pBuf);
|
||||||
taosArrayDestroy(pQInfo->tableqinfoGroupInfo.pGroupList);
|
taosArrayDestroy(pQInfo->tableqinfoGroupInfo.pGroupList);
|
||||||
|
|
Loading…
Reference in New Issue