From 18fd1c6c269cede12bd85c8fb2753d0084327b1e Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Wed, 15 Jan 2020 18:54:35 +0800 Subject: [PATCH] fix memory leaks --- src/client/src/tscFunctionImpl.c | 3 ++- src/inc/ttypes.h | 2 +- src/system/detail/src/vnodeQueryImpl.c | 18 ++++++++++-------- src/util/src/ttypes.c | 2 +- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/client/src/tscFunctionImpl.c b/src/client/src/tscFunctionImpl.c index 29f6f2dd26..2aa45b5128 100644 --- a/src/client/src/tscFunctionImpl.c +++ b/src/client/src/tscFunctionImpl.c @@ -3282,12 +3282,13 @@ 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); 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) { diff --git a/src/inc/ttypes.h b/src/inc/ttypes.h index 0f8eb2d58c..db6490f840 100644 --- a/src/inc/ttypes.h +++ b/src/inc/ttypes.h @@ -73,7 +73,7 @@ void tVariantCreateFromBinary(tVariant *pVar, char *pz, uint32_t len, uint32_t t void tVariantDestroy(tVariant *pV); -void tVariantAssign(tVariant *pDst, tVariant *pSrc); +void tVariantAssign(tVariant *pDst, const tVariant *pSrc); int32_t tVariantToString(tVariant *pVar, char *dst); diff --git a/src/system/detail/src/vnodeQueryImpl.c b/src/system/detail/src/vnodeQueryImpl.c index ac6f845f91..687a5c3729 100644 --- a/src/system/detail/src/vnodeQueryImpl.c +++ b/src/system/detail/src/vnodeQueryImpl.c @@ -2092,7 +2092,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; @@ -2180,15 +2180,17 @@ 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; + if (pSqlFuncMsg->arg[j].argType == TSDB_DATA_TYPE_BINARY || + 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 diff --git a/src/util/src/ttypes.c b/src/util/src/ttypes.c index dc2ccc9af0..b4480f41cb 100644 --- a/src/util/src/ttypes.c +++ b/src/util/src/ttypes.c @@ -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; *pDst = *pSrc;