提交 a63b848a 编写于 作者: H hjxilinx

fix memory leaks

上级 eb2def1e
......@@ -492,12 +492,12 @@ static void setInitialValueForRangeQueryCondition(tSKipListQueryCond *q, int8_t
case TSDB_DATA_TYPE_NCHAR:
case TSDB_DATA_TYPE_BINARY: {
q->upperBnd.nType = type;
q->upperBnd.pz = "\0";
q->upperBnd.pz = NULL;
q->upperBnd.nLen = -1;
q->lowerBnd.nType = type;
q->lowerBnd.pz = "\0";
q->lowerBnd.nLen = 0;
q->lowerBnd.pz = NULL;
q->lowerBnd.nLen = -1;
}
}
}
......
......@@ -3272,7 +3272,7 @@ char *arithmetic_callback_function(void *param, char *name, int32_t colId) {
static void arithmetic_function(SQLFunctionCtx *pCtx) {
GET_RES_INFO(pCtx)->numOfRes += pCtx->size;
SArithmeticSupport *sas = (SArithmeticSupport *)pCtx->param[0].pz;
SArithmeticSupport *sas = (SArithmeticSupport *)pCtx->param[1].pz;
tSQLBinaryExprCalcTraverse(sas->pExpr->pBinExprInfo.pBinExpr, pCtx->size, pCtx->aOutputBuf, sas, pCtx->order,
arithmetic_callback_function);
......@@ -3282,7 +3282,7 @@ static void arithmetic_function(SQLFunctionCtx *pCtx) {
static void arithmetic_function_f(SQLFunctionCtx *pCtx, int32_t index) {
INC_INIT_VAL(pCtx, 1);
SArithmeticSupport *sas = (SArithmeticSupport *)pCtx->param[0].pz;
SArithmeticSupport *sas = (SArithmeticSupport *)pCtx->param[1].pz;
sas->offset = index;
tSQLBinaryExprCalcTraverse(sas->pExpr->pBinExprInfo.pBinExpr, 1, pCtx->aOutputBuf, sas, pCtx->order,
......
......@@ -5205,6 +5205,13 @@ void addGroupInfoForSubquery(SSqlObj* pParentObj, SSqlObj* pSql, int32_t tableIn
}
}
// limit the output to be 1 for each state value
static void doLimitOutputNormalColOfGroupby(SSqlExpr* pExpr) {
int32_t outputRow = 1;
tVariantCreateFromBinary(&pExpr->param[0], (char*) &outputRow, sizeof(int32_t), TSDB_DATA_TYPE_INT);
pExpr->numOfParams = 1;
}
void doAddGroupColumnForSubquery(SSqlCmd* pCmd, int32_t tagIndex) {
int32_t index = pCmd->groupbyExpr.columnInfo[tagIndex].colIdx;
......@@ -5217,9 +5224,8 @@ void doAddGroupColumnForSubquery(SSqlCmd* pCmd, int32_t tagIndex) {
pSchema->bytes, pSchema->bytes);
pExpr->colInfo.flag = TSDB_COL_NORMAL;
pExpr->param[0].i64Key = 1;
pExpr->numOfParams = 1;
doLimitOutputNormalColOfGroupby(pExpr);
// NOTE: tag column does not add to source column list
SColumnList list = {0};
list.num = 1;
......@@ -5263,8 +5269,7 @@ static void doUpdateSqlFunctionForColPrj(SSqlCmd* pCmd) {
for (int32_t j = 0; j < pCmd->groupbyExpr.numOfGroupCols; ++j) {
if (pExpr->colInfo.colId == pCmd->groupbyExpr.columnInfo[j].colId) {
qualifiedCol = true;
pExpr->param[0].i64Key = 1; // limit the output to be 1 for each state value
doLimitOutputNormalColOfGroupby(pExpr);
pExpr->numOfParams = 1;
break;
}
......
......@@ -2028,7 +2028,7 @@ void setExecParams(SQuery *pQuery, SQLFunctionCtx *pCtx, int64_t startQueryTimes
pCtx->ptsList = (int64_t *)(primaryColumnData + startOffset * TSDB_KEYSIZE);
} else if (functionId == TSDB_FUNC_ARITHM) {
pCtx->param[0].pz = param;
pCtx->param[1].pz = param;
}
pCtx->startOffset = startOffset;
......@@ -2117,14 +2117,15 @@ static int32_t setupQueryRuntimeEnv(SMeterObj *pMeterObj, SQuery *pQuery, SQuery
pCtx->order = pQuery->order.order;
pCtx->functionId = pSqlFuncMsg->functionId;
/*
* tricky: in case of char array parameters, we employ the shallow copy
* method and get the ownership of the char array, it later release the allocated memory if exists
*/
pCtx->numOfParams = pSqlFuncMsg->numOfParams;
for (int32_t j = 0; j < pCtx->numOfParams; ++j) {
pCtx->param[j].nType = pSqlFuncMsg->arg[j].argType;
pCtx->param[j].i64Key = pSqlFuncMsg->arg[j].argValue.i64;
int16_t type = pSqlFuncMsg->arg[j].argType;
int16_t bytes = pSqlFuncMsg->arg[j].argBytes;
if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) {
tVariantCreateFromBinary(&pCtx->param[j], pSqlFuncMsg->arg->argValue.pz, bytes, type);
} else {
tVariantCreateFromBinary(&pCtx->param[j], (char*) &pSqlFuncMsg->arg[j].argValue.i64, bytes, type);
}
}
// set the order information for top/bottom query
......
......@@ -163,10 +163,9 @@ void tVariantCreateFromBinary(tVariant *pVar, char *pz, uint32_t len, uint32_t t
void tVariantDestroy(tVariant *pVar) {
if (pVar == NULL) return;
if ((pVar->nType == TSDB_DATA_TYPE_BINARY || pVar->nType == TSDB_DATA_TYPE_NCHAR) && pVar->nLen > 0) {
if (pVar->nType == TSDB_DATA_TYPE_BINARY || pVar->nType == TSDB_DATA_TYPE_NCHAR) {
free(pVar->pz);
pVar->pz = NULL;
pVar->nLen = 0;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册