diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 7d0ac09e66c14160f4dd715f0c44cec40674549c..a1c50b1518529c62dce6b7cce8e4eb3f9ea73d74 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -217,10 +217,12 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) { STscObj *pObj = pSql->pTscObj; // tscTrace("%p msg:%s is received from server", pSql, taosMsg[rpcMsg->msgType]); - if (pSql->freed || pObj->signature != pObj) { + if (pObj->signature != pObj) { tscTrace("%p sql is already released or DB connection is closed, freed:%d pObj:%p signature:%p", pSql, pSql->freed, pObj, pObj->signature); - tscFreeSqlObj(pSql); + if (pSql != pObj->pSql) { + tscFreeSqlObj(pSql); + } rpcFreeCont(rpcMsg->pCont); return; } @@ -1867,8 +1869,8 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) { return TSDB_CODE_CLI_OUT_OF_MEMORY; } - free(pTableMeta); tscTrace("%p recv table meta: %"PRId64 ", tid:%d, name:%s", pSql, pTableMeta->uid, pTableMeta->sid, pTableMetaInfo->name); + free(pTableMeta); return TSDB_CODE_SUCCESS; } diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 14605a571deefbf5543de7ebc57287f6a2eedaac..7a6cce4d7f70140a6de7c1727e90f05ba9e9c363 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -576,26 +576,22 @@ void taos_free_result_imp(TAOS_RES *res, int keepCmd) { * for each subquery. Because the failure of execution tsProcessSql may trigger the callback function * be executed, and the retry efforts may result in double free the resources, e.g.,SRetrieveSupport */ - if ((pCmd->command == TSDB_SQL_SELECT || pCmd->command == TSDB_SQL_SHOW || pCmd->command == TSDB_SQL_RETRIEVE || - pCmd->command == TSDB_SQL_FETCH) && - (pRes->code != TSDB_CODE_QUERY_CANCELLED && ((pRes->numOfRows > 0 && pCmd->command < TSDB_SQL_LOCAL && pRes->completed == false) || - (pRes->code == TSDB_CODE_SUCCESS && pRes->numOfRows == 0 && pCmd->command == TSDB_SQL_SELECT && - pSql->pStream == NULL && pTableMetaInfo->pTableMeta != NULL)))) { + if ((pCmd->command == TSDB_SQL_SELECT || + pCmd->command == TSDB_SQL_SHOW || + pCmd->command == TSDB_SQL_RETRIEVE || + pCmd->command == TSDB_SQL_FETCH) && + (pRes->code != TSDB_CODE_QUERY_CANCELLED && ((pCmd->command < TSDB_SQL_LOCAL && pRes->completed == false) || + (pRes->code == TSDB_CODE_SUCCESS && pCmd->command == TSDB_SQL_SELECT && pSql->pStream == NULL && pTableMetaInfo->pTableMeta != NULL)))) { pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH; - tscTrace("%p code:%d, numOfRows:%d, command:%d", pSql, pRes->code, pRes->numOfRows, pCmd->command); + tscTrace("%p send msg to free qhandle in vnode, code:%d, numOfRows:%d, command:%s", pSql, pRes->code, pRes->numOfRows, + sqlCmd[pCmd->command]); pSql->freed = 1; tscProcessSql(pSql); - - /* - * If release connection msg is sent to vnode, the corresponding SqlObj for async query can not be freed instantly, - * since its free operation is delegated to callback function, which is tscProcessMsgFromServer. - */ - STscObj* pObj = pSql->pTscObj; - if (pObj->pSql == pSql) { - pObj->pSql = NULL; - } + + // waits for response and then goes on + sem_wait(&pSql->rspSem); } else { // if no free resource msg is sent to vnode, we free this object immediately. STscObj* pTscObj = pSql->pTscObj; diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index ec9908ae969bbcb8d65c8c59603899bcfe9bdcf8..4c8722ecea421d1509a99e7396b145dbb266b5d4 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -423,6 +423,8 @@ void tscFreeSqlObj(SSqlObj* pSql) { tfree(pCmd->payload); pCmd->allocSize = 0; + + tfree(pSql->sqlstr); free(pSql); }