提交 3f20f177 编写于 作者: H Haojun Liao

[TD-225] fix memory leaks.

上级 25b47131
...@@ -6072,7 +6072,7 @@ static int32_t buildArithmeticExprFromMsg(SExprInfo *pArithExprInfo, SQueryTable ...@@ -6072,7 +6072,7 @@ static int32_t buildArithmeticExprFromMsg(SExprInfo *pArithExprInfo, SQueryTable
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t createQFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, int32_t numOfOutput, SExprInfo **pExprInfo, SSqlFuncMsg **pExprMsg, static int32_t createQueryFuncExprFromMsg(SQueryTableMsg *pQueryMsg, int32_t numOfOutput, SExprInfo **pExprInfo, SSqlFuncMsg **pExprMsg,
SColumnInfo* pTagCols) { SColumnInfo* pTagCols) {
*pExprInfo = NULL; *pExprInfo = NULL;
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
...@@ -6371,7 +6371,7 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SSqlGroupbyExpr *pGrou ...@@ -6371,7 +6371,7 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SSqlGroupbyExpr *pGrou
pQuery->limit.offset = pQueryMsg->offset; pQuery->limit.offset = pQueryMsg->offset;
pQuery->order.order = pQueryMsg->order; pQuery->order.order = pQueryMsg->order;
pQuery->order.orderColId = pQueryMsg->orderColId; pQuery->order.orderColId = pQueryMsg->orderColId;
pQuery->pExpr1 = pExprs; pQuery->pExpr1 = pExprs;
pQuery->pExpr2 = pSecExprs; pQuery->pExpr2 = pSecExprs;
pQuery->numOfExpr2 = pQueryMsg->secondStageOutput; pQuery->numOfExpr2 = pQueryMsg->secondStageOutput;
pQuery->pGroupbyExpr = pGroupbyExpr; pQuery->pGroupbyExpr = pGroupbyExpr;
...@@ -6634,6 +6634,22 @@ static void doDestroyTableQueryInfo(STableGroupInfo* pTableqinfoGroupInfo) { ...@@ -6634,6 +6634,22 @@ static void doDestroyTableQueryInfo(STableGroupInfo* pTableqinfoGroupInfo) {
pTableqinfoGroupInfo->numOfTables = 0; pTableqinfoGroupInfo->numOfTables = 0;
} }
static void* destroyQueryFuncExpr(SExprInfo* pExprInfo, int32_t numOfExpr) {
if (pExprInfo == NULL) {
assert(numOfExpr == 0);
return NULL;
}
for (int32_t i = 0; i < numOfExpr; ++i) {
if (pExprInfo[i].pExpr != NULL) {
tExprNodeDestroy(pExprInfo[i].pExpr, NULL);
}
}
tfree(pExprInfo);
return NULL;
}
static void freeQInfo(SQInfo *pQInfo) { static void freeQInfo(SQInfo *pQInfo) {
if (!isValidQInfo(pQInfo)) { if (!isValidQInfo(pQInfo)) {
return; return;
...@@ -6665,22 +6681,8 @@ static void freeQInfo(SQInfo *pQInfo) { ...@@ -6665,22 +6681,8 @@ static void freeQInfo(SQInfo *pQInfo) {
} }
} }
if (pQuery->pExpr1 != NULL) { pQuery->pExpr1 = destroyQueryFuncExpr(pQuery->pExpr1, pQuery->numOfOutput);
for (int32_t i = 0; i < pQuery->numOfOutput; ++i) { pQuery->pExpr2 = destroyQueryFuncExpr(pQuery->pExpr2, pQuery->numOfExpr2);
SExprInfo *pExprInfo = &pQuery->pExpr1[i];
if (pExprInfo->pExpr != NULL) {
tExprTreeDestroy(&pExprInfo->pExpr, NULL);
}
}
tfree(pQuery->pExpr1);
}
if (pQuery->pGroupbyExpr != NULL) {
taosArrayDestroy(pQuery->pGroupbyExpr->columnInfo);
tfree(pQuery->pGroupbyExpr);
}
tfree(pQuery->tagColList); tfree(pQuery->tagColList);
tfree(pQuery->pFilterInfo); tfree(pQuery->pFilterInfo);
...@@ -6693,6 +6695,11 @@ static void freeQInfo(SQInfo *pQInfo) { ...@@ -6693,6 +6695,11 @@ static void freeQInfo(SQInfo *pQInfo) {
tfree(pQuery->colList); tfree(pQuery->colList);
} }
if (pQuery->pGroupbyExpr != NULL) {
taosArrayDestroy(pQuery->pGroupbyExpr->columnInfo);
tfree(pQuery->pGroupbyExpr);
}
tfree(pQuery); tfree(pQuery);
} }
...@@ -6824,12 +6831,12 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi ...@@ -6824,12 +6831,12 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi
goto _over; goto _over;
} }
if ((code = createQFunctionExprFromMsg(pQueryMsg, pQueryMsg->numOfOutput, &pExprs, pExprMsg, pTagColumnInfo)) != TSDB_CODE_SUCCESS) { if ((code = createQueryFuncExprFromMsg(pQueryMsg, pQueryMsg->numOfOutput, &pExprs, pExprMsg, pTagColumnInfo)) != TSDB_CODE_SUCCESS) {
goto _over; goto _over;
} }
if (pSecExprMsg != NULL) { if (pSecExprMsg != NULL) {
if ((code = createQFunctionExprFromMsg(pQueryMsg, pQueryMsg->secondStageOutput, &pSecExprs, pSecExprMsg, pTagColumnInfo)) != TSDB_CODE_SUCCESS) { if ((code = createQueryFuncExprFromMsg(pQueryMsg, pQueryMsg->secondStageOutput, &pSecExprs, pSecExprMsg, pTagColumnInfo)) != TSDB_CODE_SUCCESS) {
goto _over; goto _over;
} }
} }
...@@ -6892,7 +6899,9 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi ...@@ -6892,7 +6899,9 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi
} }
(*pQInfo) = createQInfoImpl(pQueryMsg, pGroupbyExpr, pExprs, pSecExprs, &tableGroupInfo, pTagColumnInfo, isSTableQuery); (*pQInfo) = createQInfoImpl(pQueryMsg, pGroupbyExpr, pExprs, pSecExprs, &tableGroupInfo, pTagColumnInfo, isSTableQuery);
pExprs = NULL; pExprs = NULL;
pSecExprs = NULL;
pGroupbyExpr = NULL; pGroupbyExpr = NULL;
pTagColumnInfo = NULL; pTagColumnInfo = NULL;
...@@ -6907,13 +6916,19 @@ _over: ...@@ -6907,13 +6916,19 @@ _over:
free(tagCond); free(tagCond);
free(tbnameCond); free(tbnameCond);
free(pGroupColIndex); free(pGroupColIndex);
if (pGroupbyExpr != NULL) { if (pGroupbyExpr != NULL) {
taosArrayDestroy(pGroupbyExpr->columnInfo); taosArrayDestroy(pGroupbyExpr->columnInfo);
free(pGroupbyExpr); free(pGroupbyExpr);
} }
free(pTagColumnInfo); free(pTagColumnInfo);
free(pExprs); free(pExprs);
free(pSecExprs);
free(pExprMsg); free(pExprMsg);
free(pSecExprMsg);
taosArrayDestroy(pTableIdList); taosArrayDestroy(pTableIdList);
for (int32_t i = 0; i < pQueryMsg->numOfCols; i++) { for (int32_t i = 0; i < pQueryMsg->numOfCols; i++) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册