提交 4f6d3b56 编写于 作者: H Haojun Liao

[td-225] fix memory leaks.

上级 d18ff90c
...@@ -119,7 +119,6 @@ typedef struct SInternalField { ...@@ -119,7 +119,6 @@ typedef struct SInternalField {
TAOS_FIELD field; TAOS_FIELD field;
bool visible; bool visible;
SExprInfo *pExpr; SExprInfo *pExpr;
// SExprFilter *pFieldFilters;
} SInternalField; } SInternalField;
typedef struct SFieldInfo { typedef struct SFieldInfo {
......
...@@ -829,6 +829,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC ...@@ -829,6 +829,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC
index = 0; index = 0;
sToken = tStrGetToken(sql, &index, false); sToken = tStrGetToken(sql, &index, false);
if (sToken.type != TK_TAGS && sToken.type != TK_LP) { if (sToken.type != TK_TAGS && sToken.type != TK_LP) {
tscDestroyBoundColumnInfo(&spd);
return tscInvalidSQLErrMsg(pCmd->payload, "keyword TAGS expected", sToken.z); return tscInvalidSQLErrMsg(pCmd->payload, "keyword TAGS expected", sToken.z);
} }
...@@ -841,6 +842,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC ...@@ -841,6 +842,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC
char* end = NULL; char* end = NULL;
code = parseBoundColumns(pCmd, &spd, pTagSchema, sql, &end); code = parseBoundColumns(pCmd, &spd, pTagSchema, sql, &end);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
tscDestroyBoundColumnInfo(&spd);
return code; return code;
} }
...@@ -858,11 +860,13 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC ...@@ -858,11 +860,13 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC
sql += index; sql += index;
if (sToken.type != TK_LP) { if (sToken.type != TK_LP) {
tscDestroyBoundColumnInfo(&spd);
return tscInvalidSQLErrMsg(pCmd->payload, "( is expected", sToken.z); return tscInvalidSQLErrMsg(pCmd->payload, "( is expected", sToken.z);
} }
SKVRowBuilder kvRowBuilder = {0}; SKVRowBuilder kvRowBuilder = {0};
if (tdInitKVRowBuilder(&kvRowBuilder) < 0) { if (tdInitKVRowBuilder(&kvRowBuilder) < 0) {
tscDestroyBoundColumnInfo(&spd);
return TSDB_CODE_TSC_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
...@@ -875,6 +879,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC ...@@ -875,6 +879,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC
if (TK_ILLEGAL == sToken.type) { if (TK_ILLEGAL == sToken.type) {
tdDestroyKVRowBuilder(&kvRowBuilder); tdDestroyKVRowBuilder(&kvRowBuilder);
tscDestroyBoundColumnInfo(&spd);
return TSDB_CODE_TSC_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
...@@ -892,6 +897,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC ...@@ -892,6 +897,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC
code = tsParseOneColumn(pSchema, &sToken, tagVal, pCmd->payload, &sql, false, tinfo.precision); code = tsParseOneColumn(pSchema, &sToken, tagVal, pCmd->payload, &sql, false, tinfo.precision);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
tdDestroyKVRowBuilder(&kvRowBuilder); tdDestroyKVRowBuilder(&kvRowBuilder);
tscDestroyBoundColumnInfo(&spd);
return code; return code;
} }
......
...@@ -1504,24 +1504,24 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32 ...@@ -1504,24 +1504,24 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32
SInternalField* pInfo = tscFieldInfoGetInternalField(&pQueryInfo->fieldsInfo, slot); SInternalField* pInfo = tscFieldInfoGetInternalField(&pQueryInfo->fieldsInfo, slot);
if (pInfo->pExpr == NULL) { if (pInfo->pExpr == NULL) {
SExprInfo* pArithExprInfo = calloc(1, sizeof(SExprInfo)); SExprInfo* pExprInfo = calloc(1, sizeof(SExprInfo));
// arithmetic expression always return result in the format of double float // arithmetic expression always return result in the format of double float
pArithExprInfo->base.resBytes = sizeof(double); pExprInfo->base.resBytes = sizeof(double);
pArithExprInfo->base.interBytes = sizeof(double); pExprInfo->base.interBytes = sizeof(double);
pArithExprInfo->base.resType = TSDB_DATA_TYPE_DOUBLE; pExprInfo->base.resType = TSDB_DATA_TYPE_DOUBLE;
pArithExprInfo->base.functionId = TSDB_FUNC_ARITHM; pExprInfo->base.functionId = TSDB_FUNC_ARITHM;
pArithExprInfo->base.numOfParams = 1; pExprInfo->base.numOfParams = 1;
pArithExprInfo->base.resColId = getNewResColId(pQueryInfo); pExprInfo->base.resColId = getNewResColId(pQueryInfo);
int32_t ret = exprTreeFromSqlExpr(pCmd, &pArithExprInfo->pExpr, pItem->pNode, pQueryInfo, NULL, &(pArithExprInfo->base.uid)); int32_t ret = exprTreeFromSqlExpr(pCmd, &pExprInfo->pExpr, pItem->pNode, pQueryInfo, NULL, &(pExprInfo->base.uid));
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
tExprTreeDestroy(pArithExprInfo->pExpr, NULL); tExprTreeDestroy(pExprInfo->pExpr, NULL);
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), "invalid expression in select clause"); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), "invalid expression in select clause");
} }
pInfo->pExpr = pArithExprInfo; pInfo->pExpr = pExprInfo;
} }
SBufferWriter bw = tbufInitWriter(NULL, false); SBufferWriter bw = tbufInitWriter(NULL, false);
......
...@@ -1484,11 +1484,43 @@ static void destroyFilterInfo(SColumnFilterList* pFilterList) { ...@@ -1484,11 +1484,43 @@ static void destroyFilterInfo(SColumnFilterList* pFilterList) {
pFilterList->numOfFilters = 0; pFilterList->numOfFilters = 0;
} }
void* sqlExprDestroy(SExprInfo* pExpr) {
if (pExpr == NULL) {
return NULL;
}
SSqlExpr* p = &pExpr->base;
for(int32_t i = 0; i < tListLen(p->param); ++i) {
tVariantDestroy(&p->param[i]);
}
if (p->flist.numOfFilters > 0) {
tfree(p->flist.filterInfo);
}
if (pExpr->pExpr != NULL) {
tExprTreeDestroy(pExpr->pExpr, NULL);
}
tfree(pExpr);
return NULL;
}
void tscFieldInfoClear(SFieldInfo* pFieldInfo) { void tscFieldInfoClear(SFieldInfo* pFieldInfo) {
if (pFieldInfo == NULL) { if (pFieldInfo == NULL) {
return; return;
} }
if (pFieldInfo->internalField != NULL) {
size_t num = taosArrayGetSize(pFieldInfo->internalField);
for (int32_t i = 0; i < num; ++i) {
SInternalField* pfield = taosArrayGet(pFieldInfo->internalField, i);
if (pfield->pExpr != NULL && pfield->pExpr->pExpr != NULL) {
sqlExprDestroy(pfield->pExpr);
}
}
}
taosArrayDestroy(pFieldInfo->internalField); taosArrayDestroy(pFieldInfo->internalField);
tfree(pFieldInfo->final); tfree(pFieldInfo->final);
...@@ -1629,25 +1661,6 @@ SExprInfo* tscSqlExprGet(SQueryInfo* pQueryInfo, int32_t index) { ...@@ -1629,25 +1661,6 @@ SExprInfo* tscSqlExprGet(SQueryInfo* pQueryInfo, int32_t index) {
return taosArrayGetP(pQueryInfo->exprList, index); return taosArrayGetP(pQueryInfo->exprList, index);
} }
void* sqlExprDestroy(SExprInfo* pExpr) {
if (pExpr == NULL) {
return NULL;
}
SSqlExpr* p = &pExpr->base;
for(int32_t i = 0; i < tListLen(p->param); ++i) {
tVariantDestroy(&p->param[i]);
}
if (pExpr->pExpr != NULL) {
tExprTreeDestroy(pExpr->pExpr, NULL);
}
tfree(pExpr);
return NULL;
}
/* /*
* NOTE: Does not release SExprInfo here. * NOTE: Does not release SExprInfo here.
*/ */
...@@ -1715,8 +1728,11 @@ void tscSqlExprAssign(SExprInfo* dst, const SExprInfo* src) { ...@@ -1715,8 +1728,11 @@ void tscSqlExprAssign(SExprInfo* dst, const SExprInfo* src) {
assert(dst != NULL && src != NULL); assert(dst != NULL && src != NULL);
*dst = *src; *dst = *src;
if (src->base.flist.numOfFilters > 0) {
dst->base.flist.filterInfo = calloc(src->base.flist.numOfFilters, sizeof(SColumnFilterInfo)); dst->base.flist.filterInfo = calloc(src->base.flist.numOfFilters, sizeof(SColumnFilterInfo));
memcpy(dst->base.flist.filterInfo, src->base.flist.filterInfo, sizeof(SColumnFilterInfo) * src->base.flist.numOfFilters); memcpy(dst->base.flist.filterInfo, src->base.flist.filterInfo, sizeof(SColumnFilterInfo) * src->base.flist.numOfFilters);
}
dst->pExpr = exprdup(src->pExpr); dst->pExpr = exprdup(src->pExpr);
......
...@@ -430,13 +430,10 @@ typedef struct SSLimitOperatorInfo { ...@@ -430,13 +430,10 @@ typedef struct SSLimitOperatorInfo {
int64_t rowsTotal; int64_t rowsTotal;
int64_t currentOffset; int64_t currentOffset;
SLimitVal limit; SLimitVal limit;
SLimitVal slimit; SLimitVal slimit;
struct SLocalMerger *pMerger;
char **prevRow; char **prevRow;
bool hasPrev;
SArray *orderColumnList; SArray *orderColumnList;
} SSLimitOperatorInfo; } SSLimitOperatorInfo;
......
...@@ -1879,7 +1879,6 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) { ...@@ -1879,7 +1879,6 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) {
pRuntimeEnv->pool = destroyResultRowPool(pRuntimeEnv->pool); pRuntimeEnv->pool = destroyResultRowPool(pRuntimeEnv->pool);
taosArrayDestroyEx(pRuntimeEnv->prevResult, freeInterResult); taosArrayDestroyEx(pRuntimeEnv->prevResult, freeInterResult);
pRuntimeEnv->prevResult = NULL; pRuntimeEnv->prevResult = NULL;
} }
static bool needBuildResAfterQueryComplete(SQInfo* pQInfo) { static bool needBuildResAfterQueryComplete(SQInfo* pQInfo) {
...@@ -4516,6 +4515,12 @@ static void destroyGlobalAggOperatorInfo(void* param, int32_t numOfOutput) { ...@@ -4516,6 +4515,12 @@ static void destroyGlobalAggOperatorInfo(void* param, int32_t numOfOutput) {
tfree(pInfo->currentGroupColData); tfree(pInfo->currentGroupColData);
} }
static void destroySlimitOperatorInfo(void* param, int32_t numOfOutput) {
SSLimitOperatorInfo *pInfo = (SSLimitOperatorInfo*) param;
taosArrayDestroy(pInfo->orderColumnList);
tfree(pInfo->prevRow);
}
SOperatorInfo* createGlobalAggregateOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SOperatorInfo* createGlobalAggregateOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream,
SExprInfo* pExpr, int32_t numOfOutput, void* param) { SExprInfo* pExpr, int32_t numOfOutput, void* param) {
SMultiwayMergeInfo* pInfo = calloc(1, sizeof(SMultiwayMergeInfo)); SMultiwayMergeInfo* pInfo = calloc(1, sizeof(SMultiwayMergeInfo));
...@@ -5598,7 +5603,6 @@ SOperatorInfo* createSLimitOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperator ...@@ -5598,7 +5603,6 @@ SOperatorInfo* createSLimitOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperator
SQueryAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; SQueryAttr* pQueryAttr = pRuntimeEnv->pQueryAttr;
pInfo->orderColumnList = getResultGroupCheckColumns(pQueryAttr); pInfo->orderColumnList = getResultGroupCheckColumns(pQueryAttr);
pInfo->pMerger = pMerger;
pInfo->slimit = pQueryAttr->slimit; pInfo->slimit = pQueryAttr->slimit;
pInfo->limit = pQueryAttr->limit; pInfo->limit = pQueryAttr->limit;
...@@ -5632,7 +5636,7 @@ SOperatorInfo* createSLimitOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperator ...@@ -5632,7 +5636,7 @@ SOperatorInfo* createSLimitOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperator
pOperator->exec = doSLimit; pOperator->exec = doSLimit;
pOperator->info = pInfo; pOperator->info = pInfo;
pOperator->pRuntimeEnv = pRuntimeEnv; pOperator->pRuntimeEnv = pRuntimeEnv;
pOperator->cleanup = destroySlimitOperatorInfo;
return pOperator; return pOperator;
} }
...@@ -6974,6 +6978,10 @@ static void* destroyQueryFuncExpr(SExprInfo* pExprInfo, int32_t numOfExpr) { ...@@ -6974,6 +6978,10 @@ static void* destroyQueryFuncExpr(SExprInfo* pExprInfo, int32_t numOfExpr) {
if (pExprInfo[i].base.flist.filterInfo) { if (pExprInfo[i].base.flist.filterInfo) {
freeColumnFilterInfo(pExprInfo[i].base.flist.filterInfo, pExprInfo[i].base.flist.numOfFilters); freeColumnFilterInfo(pExprInfo[i].base.flist.filterInfo, pExprInfo[i].base.flist.numOfFilters);
} }
for(int32_t j = 0; j < pExprInfo[i].base.numOfParams; ++j) {
tVariantDestroy(&pExprInfo[i].base.param[j]);
}
} }
tfree(pExprInfo); tfree(pExprInfo);
...@@ -6991,40 +6999,13 @@ void freeQInfo(SQInfo *pQInfo) { ...@@ -6991,40 +6999,13 @@ void freeQInfo(SQInfo *pQInfo) {
releaseQueryBuf(pRuntimeEnv->tableqinfoGroupInfo.numOfTables); releaseQueryBuf(pRuntimeEnv->tableqinfoGroupInfo.numOfTables);
doDestroyTableQueryInfo(&pRuntimeEnv->tableqinfoGroupInfo); doDestroyTableQueryInfo(&pRuntimeEnv->tableqinfoGroupInfo);
teardownQueryRuntimeEnv(&pQInfo->runtimeEnv); teardownQueryRuntimeEnv(&pQInfo->runtimeEnv);
SQueryAttr *pQueryAttr = pQInfo->runtimeEnv.pQueryAttr; SQueryAttr *pQueryAttr = pQInfo->runtimeEnv.pQueryAttr;
if (pQueryAttr != NULL) { freeQueryAttr(pQueryAttr);
if (pQueryAttr->fillVal != NULL) {
tfree(pQueryAttr->fillVal);
}
pQueryAttr->pFilterInfo = doDestroyFilterInfo(pQueryAttr->pFilterInfo, pQueryAttr->numOfFilterCols);
pQueryAttr->pExpr1 = destroyQueryFuncExpr(pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
pQueryAttr->pExpr2 = destroyQueryFuncExpr(pQueryAttr->pExpr2, pQueryAttr->numOfExpr2);
pQueryAttr->pExpr3 = destroyQueryFuncExpr(pQueryAttr->pExpr3, pQueryAttr->numOfExpr3);
tfree(pQueryAttr->tagColList);
if (pQueryAttr->tableCols != NULL) {
for (int32_t i = 0; i < pQueryAttr->numOfCols; i++) {
SColumnInfo *column = pQueryAttr->tableCols + i;
freeColumnFilterInfo(column->flist.filterInfo, column->flist.numOfFilters);
}
tfree(pQueryAttr->tableCols);
}
if (pQueryAttr->pGroupbyExpr != NULL) {
taosArrayDestroy(pQueryAttr->pGroupbyExpr->columnInfo);
tfree(pQueryAttr->pGroupbyExpr);
}
}
tsdbDestroyTableGroup(&pQueryAttr->tableGroupInfo); tsdbDestroyTableGroup(&pQueryAttr->tableGroupInfo);
tfree(pQInfo->pBuf); tfree(pQInfo->pBuf);
tfree(pQInfo->sql); tfree(pQInfo->sql);
...@@ -7182,15 +7163,11 @@ void freeQueryAttr(SQueryAttr* pQueryAttr) { ...@@ -7182,15 +7163,11 @@ void freeQueryAttr(SQueryAttr* pQueryAttr) {
tfree(pQueryAttr->fillVal); tfree(pQueryAttr->fillVal);
} }
for (int32_t i = 0; i < pQueryAttr->numOfFilterCols; ++i) { pQueryAttr->pFilterInfo = doDestroyFilterInfo(pQueryAttr->pFilterInfo, pQueryAttr->numOfFilterCols);
SSingleColumnFilterInfo* pColFilter = &pQueryAttr->pFilterInfo[i];
if (pColFilter->numOfFilters > 0) {
tfree(pColFilter->pFilters);
}
}
pQueryAttr->pExpr1 = destroyQueryFuncExpr(pQueryAttr->pExpr1, pQueryAttr->numOfOutput); pQueryAttr->pExpr1 = destroyQueryFuncExpr(pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
pQueryAttr->pExpr2 = destroyQueryFuncExpr(pQueryAttr->pExpr2, pQueryAttr->numOfExpr2); pQueryAttr->pExpr2 = destroyQueryFuncExpr(pQueryAttr->pExpr2, pQueryAttr->numOfExpr2);
pQueryAttr->pExpr3 = destroyQueryFuncExpr(pQueryAttr->pExpr3, pQueryAttr->numOfExpr3);
tfree(pQueryAttr->tagColList); tfree(pQueryAttr->tagColList);
tfree(pQueryAttr->pFilterInfo); tfree(pQueryAttr->pFilterInfo);
......
...@@ -788,7 +788,6 @@ void destroySqlNode(SSqlNode *pSqlNode) { ...@@ -788,7 +788,6 @@ void destroySqlNode(SSqlNode *pSqlNode) {
} }
tSqlExprListDestroy(pSqlNode->pSelNodeList); tSqlExprListDestroy(pSqlNode->pSelNodeList);
pSqlNode->pSelNodeList = NULL; pSqlNode->pSelNodeList = NULL;
tSqlExprDestroy(pSqlNode->pWhere); tSqlExprDestroy(pSqlNode->pWhere);
...@@ -805,6 +804,7 @@ void destroySqlNode(SSqlNode *pSqlNode) { ...@@ -805,6 +804,7 @@ void destroySqlNode(SSqlNode *pSqlNode) {
taosArrayDestroyEx(pSqlNode->fillType, freeVariant); taosArrayDestroyEx(pSqlNode->fillType, freeVariant);
pSqlNode->fillType = NULL; pSqlNode->fillType = NULL;
tSqlExprDestroy(pSqlNode->pHaving);
free(pSqlNode); free(pSqlNode);
} }
......
...@@ -164,10 +164,9 @@ void *simExecuteScript(void *inputScript) { ...@@ -164,10 +164,9 @@ void *simExecuteScript(void *inputScript) {
} }
if (script->killed || script->linePos >= script->numOfLines) { if (script->killed || script->linePos >= script->numOfLines) {
printf("killed ---------------------->\n");
script = simProcessCallOver(script); script = simProcessCallOver(script);
if (script == NULL) { if (script == NULL) {
printf("abort now!\n"); simDebug("sim test abort now!");
break; break;
} }
} else { } else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册