提交 c49179ea 编写于 作者: D dapan1121

fix: fix coverity issues

上级 53e73511
...@@ -26,19 +26,25 @@ static void *taosProcessSchedQueue(void *param); ...@@ -26,19 +26,25 @@ static void *taosProcessSchedQueue(void *param);
static void taosDumpSchedulerStatus(void *qhandle, void *tmrId); static void taosDumpSchedulerStatus(void *qhandle, void *tmrId);
void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *label, SSchedQueue *pSched) { void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *label, SSchedQueue *pSched) {
bool schedMalloced = false;
if (NULL == pSched) { if (NULL == pSched) {
pSched = (SSchedQueue *)taosMemoryCalloc(sizeof(SSchedQueue), 1); pSched = (SSchedQueue *)taosMemoryCalloc(sizeof(SSchedQueue), 1);
if (pSched == NULL) { if (pSched == NULL) {
uError("%s: no enough memory for pSched", label); uError("%s: no enough memory for pSched", label);
return NULL; return NULL;
} }
schedMalloced = true;
} }
pSched->queue = (SSchedMsg *)taosMemoryCalloc(sizeof(SSchedMsg), queueSize); pSched->queue = (SSchedMsg *)taosMemoryCalloc(sizeof(SSchedMsg), queueSize);
if (pSched->queue == NULL) { if (pSched->queue == NULL) {
uError("%s: no enough memory for queue", label); uError("%s: no enough memory for queue", label);
taosCleanUpScheduler(pSched); taosCleanUpScheduler(pSched);
taosMemoryFree(pSched); if (schedMalloced) {
taosMemoryFree(pSched);
}
return NULL; return NULL;
} }
...@@ -46,6 +52,9 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab ...@@ -46,6 +52,9 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab
if (pSched->qthread == NULL) { if (pSched->qthread == NULL) {
uError("%s: no enough memory for qthread", label); uError("%s: no enough memory for qthread", label);
taosCleanUpScheduler(pSched); taosCleanUpScheduler(pSched);
if (schedMalloced) {
taosMemoryFree(pSched);
}
return NULL; return NULL;
} }
...@@ -58,18 +67,27 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab ...@@ -58,18 +67,27 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab
if (taosThreadMutexInit(&pSched->queueMutex, NULL) < 0) { if (taosThreadMutexInit(&pSched->queueMutex, NULL) < 0) {
uError("init %s:queueMutex failed(%s)", label, strerror(errno)); uError("init %s:queueMutex failed(%s)", label, strerror(errno));
taosCleanUpScheduler(pSched); taosCleanUpScheduler(pSched);
if (schedMalloced) {
taosMemoryFree(pSched);
}
return NULL; return NULL;
} }
if (tsem_init(&pSched->emptySem, 0, (uint32_t)pSched->queueSize) != 0) { if (tsem_init(&pSched->emptySem, 0, (uint32_t)pSched->queueSize) != 0) {
uError("init %s:empty semaphore failed(%s)", label, strerror(errno)); uError("init %s:empty semaphore failed(%s)", label, strerror(errno));
taosCleanUpScheduler(pSched); taosCleanUpScheduler(pSched);
if (schedMalloced) {
taosMemoryFree(pSched);
}
return NULL; return NULL;
} }
if (tsem_init(&pSched->fullSem, 0, 0) != 0) { if (tsem_init(&pSched->fullSem, 0, 0) != 0) {
uError("init %s:full semaphore failed(%s)", label, strerror(errno)); uError("init %s:full semaphore failed(%s)", label, strerror(errno));
taosCleanUpScheduler(pSched); taosCleanUpScheduler(pSched);
if (schedMalloced) {
taosMemoryFree(pSched);
}
return NULL; return NULL;
} }
...@@ -83,6 +101,9 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab ...@@ -83,6 +101,9 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab
if (code != 0) { if (code != 0) {
uError("%s: failed to create rpc thread(%s)", label, strerror(errno)); uError("%s: failed to create rpc thread(%s)", label, strerror(errno));
taosCleanUpScheduler(pSched); taosCleanUpScheduler(pSched);
if (schedMalloced) {
taosMemoryFree(pSched);
}
return NULL; return NULL;
} }
++pSched->numOfThreads; ++pSched->numOfThreads;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册