From 96d4f0a7a75e5feff6ce405e9ec5a31c34e0bd30 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 24 Nov 2021 15:48:21 +0800 Subject: [PATCH] [TD-11316] fix mem leak when taos_connect failed --- src/client/src/tscSql.c | 3 +++ src/client/src/tscSystem.c | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 89da3c5640..380ce65133 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -195,6 +195,9 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, tsem_wait(&pSql->rspSem); pSql->pTscObj->pClusterInfo = (SClusterInfo *)tscAcquireClusterInfo(pSql->pTscObj->clusterId); + if (pSql->pTscObj->pClusterInfo == NULL) { + assert(pSql->res.code != TSDB_CODE_SUCCESS); + } if (pSql->res.code != TSDB_CODE_SUCCESS) { terrno = pSql->res.code; if (terrno ==TSDB_CODE_RPC_FQDN_ERROR) { diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index f6614fdb79..bc8d0db485 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -133,8 +133,11 @@ void tscClusterInfoDestroy(SClusterInfo *pObj) { void *tscAcquireClusterInfo(const char *clusterId) { pthread_mutex_lock(&clusterMutex); - size_t len = strlen(clusterId); + if (len == 0) { + pthread_mutex_unlock(&clusterMutex); + return NULL; + } SClusterInfo *pObj = NULL; SClusterInfo **ppObj = taosHashGet(tscClusterMap, clusterId, len); if (ppObj == NULL || *ppObj == NULL) { -- GitLab