diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 620e8ea57a29c75f1060ee4de6f1661ae319f07d..c4ca6793ff14a86039738ffce1ffc04dfcc42aec 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -546,6 +546,10 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { pSql->cmd.numOfParams = 0; pSql->cmd.batchSize = 0; + uint64_t handle = (uint64_t) pSql; + pSql->self = taosCachePut(tscObjCache, &handle, sizeof(uint64_t), &pSql, sizeof(uint64_t), 2*3600*1000); + T_REF_INC(pSql->pTscObj); + int32_t code = tsParseSql(pSql, true); if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { // wait for the callback function to post the semaphore @@ -574,7 +578,7 @@ int taos_stmt_close(TAOS_STMT* stmt) { free(normal->sql); } - tscFreeSqlObj(pStmt->pSql); + taos_free_result(pStmt->pSql); free(pStmt); return TSDB_CODE_SUCCESS; } diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index 93a865a78b07d4152148c3fe236f16f09ad3fb42..1ebef4ce0f5b11dac638e6d5061b8e85aa2dd2d1 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -612,7 +612,6 @@ void taos_close_stream(TAOS_STREAM *handle) { * Here, we need a check before release memory */ if (pSql->signature == pSql) { - T_REF_DEC(pSql->pTscObj); tscRemoveFromStreamList(pStream, pSql); taosTmrStopA(&(pStream->pTimer)); @@ -621,7 +620,7 @@ void taos_close_stream(TAOS_STREAM *handle) { // notify CQ to release the pStream object pStream->fp(pStream->param, NULL, NULL); - tscFreeSqlObj(pSql); + taos_free_result(pSql); pStream->pSql = NULL; taosTFree(pStream); diff --git a/src/client/src/tscSub.c b/src/client/src/tscSub.c index 76bce19668433d8819d44c8f272ad62b1d6dd034..760c5f5a514af8f90ce3e6461dfff019a766c682 100644 --- a/src/client/src/tscSub.c +++ b/src/client/src/tscSub.c @@ -152,6 +152,10 @@ static SSub* tscCreateSubscription(STscObj* pObj, const char* topic, const char* goto fail; } + uint64_t handle = (uint64_t) pSql; + pSql->self = taosCachePut(tscObjCache, &handle, sizeof(uint64_t), &pSql, sizeof(uint64_t), 2*3600*1000); + T_REF_INC(pSql->pTscObj); + code = tsParseSql(pSql, false); if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { tsem_wait(&pSub->sem); @@ -173,7 +177,11 @@ static SSub* tscCreateSubscription(STscObj* pObj, const char* topic, const char* fail: tscError("tscCreateSubscription failed at line %d, reason: %s", line, tstrerror(code)); if (pSql != NULL) { - tscFreeSqlObj(pSql); + if (pSql->self != NULL) { + taos_free_result(pSql); + } else { + tscFreeSqlObj(pSql); + } pSql = NULL; } if (pSub != NULL) { @@ -494,6 +502,10 @@ void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress) { } } + if (pSub->pSql != NULL) { + taos_free_result(pSub->pSql); + } + tscFreeSqlObj(pSub->pSql); taosArrayDestroy(pSub->progress); tsem_destroy(&pSub->sem);