From 752844b1e007e6134d4de7a93ade5fd2cdd5d980 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 16 Oct 2020 15:10:13 +0800 Subject: [PATCH] [td-1728] fix memory leaks --- src/client/inc/tscSubquery.h | 2 +- src/client/src/tscSubquery.c | 28 ++++++++++++---------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/client/inc/tscSubquery.h b/src/client/inc/tscSubquery.h index 07e0580397..7876069cce 100644 --- a/src/client/inc/tscSubquery.h +++ b/src/client/inc/tscSubquery.h @@ -28,7 +28,7 @@ void tscFetchDatablockFromSubquery(SSqlObj* pSql); void tscSetupOutputColumnIndex(SSqlObj* pSql); void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code); -SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, int32_t index); +SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, int32_t index); void tscHandleMasterJoinQuery(SSqlObj* pSql); diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 5ccb2aee8c..e47583b1a2 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -166,7 +166,7 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSupporter* pSupporter1, SJ } // todo handle failed to create sub query -SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, int32_t index) { +SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, int32_t index) { SJoinSupporter* pSupporter = calloc(1, sizeof(SJoinSupporter)); if (pSupporter == NULL) { return NULL; @@ -1300,11 +1300,11 @@ void tscHandleMasterJoinQuery(SSqlObj* pSql) { int32_t code = TSDB_CODE_SUCCESS; // todo add test - SSubqueryState *pState = calloc(1, sizeof(SSubqueryState)); - if (pState == NULL) { - code = TSDB_CODE_TSC_OUT_OF_MEMORY; - goto _error; - } +// SSubqueryState *pState = calloc(1, sizeof(SSubqueryState)); +// if (pState == NULL) { +// code = TSDB_CODE_TSC_OUT_OF_MEMORY; +// goto _error; +// } pSql->subState.numOfSub = pQueryInfo->numOfTables; @@ -1312,7 +1312,7 @@ void tscHandleMasterJoinQuery(SSqlObj* pSql) { tscDebug("%p start subquery, total:%d", pSql, pQueryInfo->numOfTables); for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) { - SJoinSupporter *pSupporter = tscCreateJoinSupporter(pSql, pState, i); + SJoinSupporter *pSupporter = tscCreateJoinSupporter(pSql, i); if (pSupporter == NULL) { // failed to create support struct, abort current query tscError("%p tableIndex:%d, failed to allocate join support object, abort further query", pSql, i); @@ -1357,8 +1357,8 @@ void tscHandleMasterJoinQuery(SSqlObj* pSql) { tscQueueAsyncRes(pSql); } -static void doCleanupSubqueries(SSqlObj *pSql, int32_t numOfSubs, SSubqueryState* pState) { - assert(numOfSubs <= pSql->subState.numOfSub && numOfSubs >= 0 && pState != NULL); +static void doCleanupSubqueries(SSqlObj *pSql, int32_t numOfSubs) { + assert(numOfSubs <= pSql->subState.numOfSub && numOfSubs >= 0); for(int32_t i = 0; i < numOfSubs; ++i) { SSqlObj* pSub = pSql->pSubs[i]; @@ -1371,8 +1371,6 @@ static void doCleanupSubqueries(SSqlObj *pSql, int32_t numOfSubs, SSubqueryState taos_free_result(pSub); } - - free(pState); } int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { @@ -1410,10 +1408,8 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { pSql->pSubs = calloc(pSql->subState.numOfSub, POINTER_BYTES); tscDebug("%p retrieved query data from %d vnode(s)", pSql, pSql->subState.numOfSub); - SSubqueryState *pState = calloc(1, sizeof(SSubqueryState)); - if (pSql->pSubs == NULL || pState == NULL) { - taosTFree(pState); + if (pSql->pSubs == NULL) { taosTFree(pSql->pSubs); pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; tscLocalReducerEnvDestroy(pMemoryBuf, pDesc, pModel, pSql->subState.numOfSub); @@ -1470,13 +1466,13 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; tscLocalReducerEnvDestroy(pMemoryBuf, pDesc, pModel, pSql->subState.numOfSub); - doCleanupSubqueries(pSql, i, pState); + doCleanupSubqueries(pSql, i); return pRes->code; // free all allocated resource } if (pRes->code == TSDB_CODE_TSC_QUERY_CANCELLED) { tscLocalReducerEnvDestroy(pMemoryBuf, pDesc, pModel, pSql->subState.numOfSub); - doCleanupSubqueries(pSql, i, pState); + doCleanupSubqueries(pSql, i); return pRes->code; } -- GitLab