From c49179eac935b6f30f9a0dfdef6f9b9fbd52e447 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Wed, 19 Oct 2022 09:35:03 +0800 Subject: [PATCH] fix: fix coverity issues --- source/util/src/tsched.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/source/util/src/tsched.c b/source/util/src/tsched.c index f524680331..467f26b362 100644 --- a/source/util/src/tsched.c +++ b/source/util/src/tsched.c @@ -26,19 +26,25 @@ static void *taosProcessSchedQueue(void *param); static void taosDumpSchedulerStatus(void *qhandle, void *tmrId); void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *label, SSchedQueue *pSched) { + bool schedMalloced = false; + if (NULL == pSched) { pSched = (SSchedQueue *)taosMemoryCalloc(sizeof(SSchedQueue), 1); if (pSched == NULL) { uError("%s: no enough memory for pSched", label); return NULL; } + + schedMalloced = true; } pSched->queue = (SSchedMsg *)taosMemoryCalloc(sizeof(SSchedMsg), queueSize); if (pSched->queue == NULL) { uError("%s: no enough memory for queue", label); taosCleanUpScheduler(pSched); - taosMemoryFree(pSched); + if (schedMalloced) { + taosMemoryFree(pSched); + } return NULL; } @@ -46,6 +52,9 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab if (pSched->qthread == NULL) { uError("%s: no enough memory for qthread", label); taosCleanUpScheduler(pSched); + if (schedMalloced) { + taosMemoryFree(pSched); + } return NULL; } @@ -58,18 +67,27 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab if (taosThreadMutexInit(&pSched->queueMutex, NULL) < 0) { uError("init %s:queueMutex failed(%s)", label, strerror(errno)); taosCleanUpScheduler(pSched); + if (schedMalloced) { + taosMemoryFree(pSched); + } return NULL; } if (tsem_init(&pSched->emptySem, 0, (uint32_t)pSched->queueSize) != 0) { uError("init %s:empty semaphore failed(%s)", label, strerror(errno)); taosCleanUpScheduler(pSched); + if (schedMalloced) { + taosMemoryFree(pSched); + } return NULL; } if (tsem_init(&pSched->fullSem, 0, 0) != 0) { uError("init %s:full semaphore failed(%s)", label, strerror(errno)); taosCleanUpScheduler(pSched); + if (schedMalloced) { + taosMemoryFree(pSched); + } return NULL; } @@ -83,6 +101,9 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab if (code != 0) { uError("%s: failed to create rpc thread(%s)", label, strerror(errno)); taosCleanUpScheduler(pSched); + if (schedMalloced) { + taosMemoryFree(pSched); + } return NULL; } ++pSched->numOfThreads;