From 3d4cc22425aeb077a07e3786b8f3ca0fb3a83444 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Sat, 28 Mar 2020 14:54:11 +0800 Subject: [PATCH] fix pServerObj memory leak in ttcpserver.c --- src/rpc/src/ttcpserver.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/rpc/src/ttcpserver.c b/src/rpc/src/ttcpserver.c index 663bfcdf8e..9d2c4e713d 100644 --- a/src/rpc/src/ttcpserver.c +++ b/src/rpc/src/ttcpserver.c @@ -389,6 +389,7 @@ void *taosInitTcpServer(char *ip, uint16_t port, char *label, int numOfThreads, pServerObj->pThreadObj = (SThreadObj *)malloc(sizeof(SThreadObj) * (size_t)numOfThreads); if (pServerObj->pThreadObj == NULL) { tError("TCP:%s no enough memory", label); + free(pServerObj); return NULL; } memset(pServerObj->pThreadObj, 0, sizeof(SThreadObj) * (size_t)numOfThreads); @@ -401,17 +402,23 @@ void *taosInitTcpServer(char *ip, uint16_t port, char *label, int numOfThreads, if (pthread_mutex_init(&(pThreadObj->threadMutex), NULL) < 0) { tError("%s failed to init TCP process data mutex, reason:%s", label, strerror(errno)); + free(pServerObj->pThreadObj); + free(pServerObj); return NULL; } if (pthread_cond_init(&(pThreadObj->fdReady), NULL) != 0) { tError("%s init TCP condition variable failed, reason:%s\n", label, strerror(errno)); + free(pServerObj->pThreadObj); + free(pServerObj); return NULL; } pThreadObj->pollFd = epoll_create(10); // size does not matter if (pThreadObj->pollFd < 0) { tError("%s failed to create TCP epoll", label); + free(pServerObj->pThreadObj); + free(pServerObj); return NULL; } @@ -419,6 +426,8 @@ void *taosInitTcpServer(char *ip, uint16_t port, char *label, int numOfThreads, pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); if (pthread_create(&(pThreadObj->thread), &thattr, (void *)taosProcessTcpData, (void *)(pThreadObj)) != 0) { tError("%s failed to create TCP process data thread, reason:%s", label, strerror(errno)); + free(pServerObj->pThreadObj); + free(pServerObj); return NULL; } @@ -430,6 +439,8 @@ void *taosInitTcpServer(char *ip, uint16_t port, char *label, int numOfThreads, pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); if (pthread_create(&(pServerObj->thread), &thattr, (void *)taosAcceptTcpConnection, (void *)(pServerObj)) != 0) { tError("%s failed to create TCP accept thread, reason:%s", label, strerror(errno)); + free(pServerObj->pThreadObj); + free(pServerObj); return NULL; } -- GitLab