fix memory leaks and refactor some codes
This commit is contained in:
parent
2c393a89dd
commit
5ddc7b4578
|
@ -251,10 +251,10 @@ typedef struct {
|
||||||
int32_t clauseIndex; // index of multiple subclause query
|
int32_t clauseIndex; // index of multiple subclause query
|
||||||
int8_t isParseFinish;
|
int8_t isParseFinish;
|
||||||
short numOfCols;
|
short numOfCols;
|
||||||
|
|
||||||
uint32_t allocSize;
|
uint32_t allocSize;
|
||||||
char * payload;
|
char * payload;
|
||||||
int payloadLen;
|
int payloadLen;
|
||||||
|
|
||||||
SQueryInfo **pQueryInfo;
|
SQueryInfo **pQueryInfo;
|
||||||
int32_t numOfClause;
|
int32_t numOfClause;
|
||||||
|
|
||||||
|
@ -413,6 +413,7 @@ int32_t tscCreateResPointerInfo(SQueryInfo *pQueryInfo, SSqlRes *pRes);
|
||||||
void tscDestroyResPointerInfo(SSqlRes *pRes);
|
void tscDestroyResPointerInfo(SSqlRes *pRes);
|
||||||
|
|
||||||
void tscFreeSqlCmdData(SSqlCmd *pCmd);
|
void tscFreeSqlCmdData(SSqlCmd *pCmd);
|
||||||
|
void tscFreeResData(SSqlObj* pSql);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* only free part of resources allocated during query.
|
* only free part of resources allocated during query.
|
||||||
|
|
|
@ -453,6 +453,10 @@ void tscDestroyLocalReducer(SSqlObj *pSql) {
|
||||||
for(int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
for(int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||||
SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[i];
|
SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[i];
|
||||||
tVariantDestroy(&pCtx->tag);
|
tVariantDestroy(&pCtx->tag);
|
||||||
|
|
||||||
|
if (pCtx->tagInfo.pTagCtxList != NULL) {
|
||||||
|
tfree(pCtx->tagInfo.pTagCtxList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tfree(pLocalReducer->pCtx);
|
tfree(pLocalReducer->pCtx);
|
||||||
|
|
|
@ -365,6 +365,39 @@ void tscFreeSqlCmdData(SSqlCmd* pCmd) {
|
||||||
tscFreeSubqueryInfo(pCmd);
|
tscFreeSubqueryInfo(pCmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tscFreeResData(SSqlObj* pSql) {
|
||||||
|
SSqlRes* pRes = &pSql->res;
|
||||||
|
|
||||||
|
tfree(pRes->pRsp);
|
||||||
|
pRes->row = 0;
|
||||||
|
|
||||||
|
pRes->rspType = 0;
|
||||||
|
pRes->rspLen = 0;
|
||||||
|
pRes->row = 0;
|
||||||
|
|
||||||
|
pRes->numOfRows = 0;
|
||||||
|
pRes->numOfTotal = 0;
|
||||||
|
pRes->numOfTotalInCurrentClause = 0;
|
||||||
|
|
||||||
|
pRes->numOfGroups = 0;
|
||||||
|
pRes->precision = 0;
|
||||||
|
pRes->numOfnchar = 0;
|
||||||
|
pRes->qhandle = 0;
|
||||||
|
|
||||||
|
pRes->offset = 0;
|
||||||
|
pRes->useconds = 0;
|
||||||
|
pRes->code = 0;
|
||||||
|
|
||||||
|
pRes->data = NULL;
|
||||||
|
|
||||||
|
tfree(pRes->pGroupRec);
|
||||||
|
|
||||||
|
tscDestroyLocalReducer(pSql);
|
||||||
|
|
||||||
|
tscDestroyResPointerInfo(pRes);
|
||||||
|
tfree(pRes->pColumnIndex);
|
||||||
|
}
|
||||||
|
|
||||||
void tscFreeSqlObjPartial(SSqlObj* pSql) {
|
void tscFreeSqlObjPartial(SSqlObj* pSql) {
|
||||||
if (pSql == NULL || pSql->signature != pSql) {
|
if (pSql == NULL || pSql->signature != pSql) {
|
||||||
return;
|
return;
|
||||||
|
@ -388,21 +421,10 @@ void tscFreeSqlObjPartial(SSqlObj* pSql) {
|
||||||
tfree(pSql->sqlstr);
|
tfree(pSql->sqlstr);
|
||||||
pthread_mutex_unlock(&pObj->mutex);
|
pthread_mutex_unlock(&pObj->mutex);
|
||||||
|
|
||||||
tfree(pRes->pRsp);
|
tscFreeResData(pSql);
|
||||||
pRes->row = 0;
|
|
||||||
pRes->numOfRows = 0;
|
|
||||||
pRes->numOfTotal = 0;
|
|
||||||
pRes->numOfTotalInCurrentClause = 0;
|
|
||||||
|
|
||||||
pRes->numOfGroups = 0;
|
|
||||||
tfree(pRes->pGroupRec);
|
|
||||||
|
|
||||||
tscDestroyLocalReducer(pSql);
|
|
||||||
|
|
||||||
tfree(pSql->pSubs);
|
tfree(pSql->pSubs);
|
||||||
pSql->numOfSubs = 0;
|
pSql->numOfSubs = 0;
|
||||||
tscDestroyResPointerInfo(pRes);
|
|
||||||
tfree(pRes->pColumnIndex);
|
|
||||||
|
|
||||||
tscFreeSqlCmdData(pCmd);
|
tscFreeSqlCmdData(pCmd);
|
||||||
}
|
}
|
||||||
|
@ -2156,12 +2178,14 @@ void tscTryQueryNextClause(SSqlObj* pSql, void (*queryFp)()) {
|
||||||
|
|
||||||
pSql->cmd.command = pQueryInfo->command;
|
pSql->cmd.command = pQueryInfo->command;
|
||||||
|
|
||||||
pRes->numOfTotal += pRes->numOfTotalInCurrentClause;
|
//backup the total number of result first
|
||||||
pRes->numOfTotalInCurrentClause = 0;
|
int64_t num = pRes->numOfTotal + pRes->numOfTotalInCurrentClause;
|
||||||
pRes->rspType = 0;
|
tscFreeResData(pSql);
|
||||||
|
|
||||||
|
pRes->numOfTotal = num;
|
||||||
|
|
||||||
pSql->numOfSubs = 0;
|
|
||||||
tfree(pSql->pSubs);
|
tfree(pSql->pSubs);
|
||||||
|
pSql->numOfSubs = 0;
|
||||||
|
|
||||||
if (pSql->fp != NULL) {
|
if (pSql->fp != NULL) {
|
||||||
pSql->fp = queryFp;
|
pSql->fp = queryFp;
|
||||||
|
|
Loading…
Reference in New Issue