提交 18fd1c6c 编写于 作者: H hjxilinx

fix memory leaks

上级 c5dc9a1d
...@@ -3282,12 +3282,13 @@ char *arithmetic_callback_function(void *param, char *name, int32_t colId) { ...@@ -3282,12 +3282,13 @@ char *arithmetic_callback_function(void *param, char *name, int32_t colId) {
static void arithmetic_function(SQLFunctionCtx *pCtx) { static void arithmetic_function(SQLFunctionCtx *pCtx) {
GET_RES_INFO(pCtx)->numOfRes += pCtx->size; 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, tSQLBinaryExprCalcTraverse(sas->pExpr->pBinExprInfo.pBinExpr, pCtx->size, pCtx->aOutputBuf, sas, pCtx->order,
arithmetic_callback_function); arithmetic_callback_function);
pCtx->aOutputBuf += pCtx->outputBytes * pCtx->size * GET_FORWARD_DIRECTION_FACTOR(pCtx->order); pCtx->aOutputBuf += pCtx->outputBytes * pCtx->size * GET_FORWARD_DIRECTION_FACTOR(pCtx->order);
pCtx->param[1].pz = NULL;
} }
static void arithmetic_function_f(SQLFunctionCtx *pCtx, int32_t index) { static void arithmetic_function_f(SQLFunctionCtx *pCtx, int32_t index) {
......
...@@ -73,7 +73,7 @@ void tVariantCreateFromBinary(tVariant *pVar, char *pz, uint32_t len, uint32_t t ...@@ -73,7 +73,7 @@ void tVariantCreateFromBinary(tVariant *pVar, char *pz, uint32_t len, uint32_t t
void tVariantDestroy(tVariant *pV); void tVariantDestroy(tVariant *pV);
void tVariantAssign(tVariant *pDst, tVariant *pSrc); void tVariantAssign(tVariant *pDst, const tVariant *pSrc);
int32_t tVariantToString(tVariant *pVar, char *dst); int32_t tVariantToString(tVariant *pVar, char *dst);
......
...@@ -2092,7 +2092,7 @@ void setExecParams(SQuery *pQuery, SQLFunctionCtx *pCtx, int64_t startQueryTimes ...@@ -2092,7 +2092,7 @@ void setExecParams(SQuery *pQuery, SQLFunctionCtx *pCtx, int64_t startQueryTimes
pCtx->ptsList = (int64_t *)(primaryColumnData + startOffset * TSDB_KEYSIZE); pCtx->ptsList = (int64_t *)(primaryColumnData + startOffset * TSDB_KEYSIZE);
} else if (functionId == TSDB_FUNC_ARITHM) { } else if (functionId == TSDB_FUNC_ARITHM) {
pCtx->param[0].pz = param; pCtx->param[1].pz = param;
} }
pCtx->startOffset = startOffset; pCtx->startOffset = startOffset;
...@@ -2180,15 +2180,17 @@ static int32_t setupQueryRuntimeEnv(SMeterObj *pMeterObj, SQuery *pQuery, SQuery ...@@ -2180,15 +2180,17 @@ static int32_t setupQueryRuntimeEnv(SMeterObj *pMeterObj, SQuery *pQuery, SQuery
pCtx->order = pQuery->order.order; pCtx->order = pQuery->order.order;
pCtx->functionId = pSqlFuncMsg->functionId; 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; pCtx->numOfParams = pSqlFuncMsg->numOfParams;
for (int32_t j = 0; j < pCtx->numOfParams; ++j) { for (int32_t j = 0; j < pCtx->numOfParams; ++j) {
pCtx->param[j].nType = pSqlFuncMsg->arg[j].argType; if (pSqlFuncMsg->arg[j].argType == TSDB_DATA_TYPE_BINARY ||
pCtx->param[j].i64Key = pSqlFuncMsg->arg[j].argValue.i64; pSqlFuncMsg->arg[j].argType == TSDB_DATA_TYPE_NCHAR) {
tVariantCreateFromBinary(&pCtx->param[j], pSqlFuncMsg->arg[j].argValue.pz,
pSqlFuncMsg->arg[j].argBytes, pSqlFuncMsg->arg[j].argType);
} else {
tVariantCreateFromBinary(&pCtx->param[j], (char*) &pSqlFuncMsg->arg[j].argValue.d,
pSqlFuncMsg->arg[j].argBytes, pSqlFuncMsg->arg[j].argType);
}
} }
// set the order information for top/bottom query // set the order information for top/bottom query
......
...@@ -169,7 +169,7 @@ void tVariantDestroy(tVariant *pVar) { ...@@ -169,7 +169,7 @@ void tVariantDestroy(tVariant *pVar) {
} }
} }
void tVariantAssign(tVariant *pDst, tVariant *pSrc) { void tVariantAssign(tVariant *pDst, const tVariant *pSrc) {
if (pSrc == NULL || pDst == NULL) return; if (pSrc == NULL || pDst == NULL) return;
*pDst = *pSrc; *pDst = *pSrc;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册