提交 5f5fdc71 编写于 作者: dengyihao's avatar dengyihao

[TD-11316]<fix> fix mem leak when taos_connect failed

上级 96d4f0a7
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "ttimer.h" #include "ttimer.h"
#include "tscProfile.h" #include "tscProfile.h"
static char clusterDefaultId[] = "clusterDefaultId";
static bool validImpl(const char* str, size_t maxsize) { static bool validImpl(const char* str, size_t maxsize) {
if (str == NULL) { if (str == NULL) {
return false; return false;
...@@ -193,11 +194,10 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, ...@@ -193,11 +194,10 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass,
tscBuildAndSendRequest(pSql, NULL); tscBuildAndSendRequest(pSql, NULL);
tsem_wait(&pSql->rspSem); tsem_wait(&pSql->rspSem);
if (0 == strlen(pSql->pTscObj->clusterId)) {
pSql->pTscObj->pClusterInfo = (SClusterInfo *)tscAcquireClusterInfo(pSql->pTscObj->clusterId); memcpy(pSql->pTscObj->clusterId, clusterDefaultId, strlen(clusterDefaultId));
if (pSql->pTscObj->pClusterInfo == NULL) {
assert(pSql->res.code != TSDB_CODE_SUCCESS);
} }
pSql->pTscObj->pClusterInfo = (SClusterInfo *)tscAcquireClusterInfo(pSql->pTscObj->clusterId);
if (pSql->res.code != TSDB_CODE_SUCCESS) { if (pSql->res.code != TSDB_CODE_SUCCESS) {
terrno = pSql->res.code; terrno = pSql->res.code;
if (terrno ==TSDB_CODE_RPC_FQDN_ERROR) { if (terrno ==TSDB_CODE_RPC_FQDN_ERROR) {
......
...@@ -134,10 +134,7 @@ void tscClusterInfoDestroy(SClusterInfo *pObj) { ...@@ -134,10 +134,7 @@ void tscClusterInfoDestroy(SClusterInfo *pObj) {
void *tscAcquireClusterInfo(const char *clusterId) { void *tscAcquireClusterInfo(const char *clusterId) {
pthread_mutex_lock(&clusterMutex); pthread_mutex_lock(&clusterMutex);
size_t len = strlen(clusterId); size_t len = strlen(clusterId);
if (len == 0) {
pthread_mutex_unlock(&clusterMutex);
return NULL;
}
SClusterInfo *pObj = NULL; SClusterInfo *pObj = NULL;
SClusterInfo **ppObj = taosHashGet(tscClusterMap, clusterId, len); SClusterInfo **ppObj = taosHashGet(tscClusterMap, clusterId, len);
if (ppObj == NULL || *ppObj == NULL) { if (ppObj == NULL || *ppObj == NULL) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册