diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index be862308f1..cea4d6882e 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -191,7 +191,7 @@ int32_t taosRenameFile(const char *oldName, const char *newName) { printf("failed to rename file %s to %s, reason:%s\n", oldName, newName, strerror(errno)); } - return !code; + return code ? 0 : 1; #else int32_t code = rename(oldName, newName); if (code < 0) { diff --git a/source/util/src/tcompression.c b/source/util/src/tcompression.c index be220c2585..fbbe970c74 100644 --- a/source/util/src/tcompression.c +++ b/source/util/src/tcompression.c @@ -2274,6 +2274,9 @@ int32_t tsCompressBool(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t return tsCompressBoolImp(pIn, nEle, pOut); } else if (cmprAlg == TWO_STAGE_COMP) { int32_t len = tsCompressBoolImp(pIn, nEle, pBuf); + if (len < 0) { + return -1; + } return tsCompressStringImp(pBuf, len, pOut, nOut); } else { assert(0); diff --git a/source/util/src/tdigest.c b/source/util/src/tdigest.c index 067580708e..1b9edf79a0 100644 --- a/source/util/src/tdigest.c +++ b/source/util/src/tdigest.c @@ -263,7 +263,7 @@ double tdigestQuantile(TDigest *t, double q) { b = c; right = (b->weight * a->mean + a->weight * b->mean) / (a->weight + b->weight); if (idx < weight_so_far + a->weight) { - double p = (idx - weight_so_far) / a->weight; + double p = (idx - weight_so_far) / (a->weight == 0) ? 1 : a->weight; return left * (1 - p) + right * p; } weight_so_far += a->weight; diff --git a/source/util/src/tencode.c b/source/util/src/tencode.c index 2267c90783..a925d1fc5e 100644 --- a/source/util/src/tencode.c +++ b/source/util/src/tencode.c @@ -109,7 +109,9 @@ void tEndEncode(SEncoder* pCoder) { pCoder->size = pNode->size; pCoder->pos = pNode->pos; - tEncodeI32(pCoder, len); + if (tEncodeI32(pCoder, len) < 0) { + return; + } TD_CODER_MOVE_POS(pCoder, len); } diff --git a/source/util/src/tenv.c b/source/util/src/tenv.c index 027918f2c6..7fe079ada4 100644 --- a/source/util/src/tenv.c +++ b/source/util/src/tenv.c @@ -54,7 +54,7 @@ int32_t taosEnvNameToCfgName(const char *envNameStr, char *cfgNameStr, int32_t c } int32_t taosEnvToCfg(const char *envStr, char *cfgStr) { - if (envStr == NULL && cfgStr == NULL) { + if (envStr == NULL || cfgStr == NULL) { return -1; } if (cfgStr != envStr) strcpy(cfgStr, envStr); diff --git a/source/util/src/thash.c b/source/util/src/thash.c index e7b2d9638f..eb20024ff9 100644 --- a/source/util/src/thash.c +++ b/source/util/src/thash.c @@ -639,7 +639,7 @@ void taosHashTableResize(SHashObj *pHashObj) { } int64_t st = taosGetTimestampUs(); - void *pNewEntryList = taosMemoryRealloc(pHashObj->hashList, sizeof(void *) * newCapacity); + SHashEntry **pNewEntryList = taosMemoryRealloc(pHashObj->hashList, sizeof(SHashEntry *) * newCapacity); if (pNewEntryList == NULL) { // uDebug("cache resize failed due to out of memory, capacity remain:%zu", pHashObj->capacity); return; diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index 9d97cf7ab2..09d12029bc 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -207,7 +207,10 @@ static void taosKeepOldLog(char *oldName) { char fileName[LOG_FILE_NAME_LEN + 20]; snprintf(fileName, LOG_FILE_NAME_LEN + 20, "%s.%" PRId64, tsLogObj.logName, fileSec); - taosRenameFile(oldName, fileName); + if (taosRenameFile(oldName, fileName) != 0) { + return; + } + if (tsLogKeepDays < 0) { char compressFileName[LOG_FILE_NAME_LEN + 20]; snprintf(compressFileName, LOG_FILE_NAME_LEN + 20, "%s.%" PRId64 ".gz", tsLogObj.logName, fileSec); diff --git a/source/util/src/tlrucache.c b/source/util/src/tlrucache.c index 83cfbb2ad1..0ea7258828 100644 --- a/source/util/src/tlrucache.c +++ b/source/util/src/tlrucache.c @@ -337,6 +337,7 @@ static int taosLRUCacheShardInit(SLRUCacheShard *shard, size_t capacity, bool st taosThreadMutexInit(&shard->mutex, NULL); + taosThreadMutexLock(&shard->mutex); shard->capacity = 0; shard->highPriPoolUsage = 0; shard->strictCapacity = strict; @@ -349,6 +350,7 @@ static int taosLRUCacheShardInit(SLRUCacheShard *shard, size_t capacity, bool st shard->lru.next = &shard->lru; shard->lru.prev = &shard->lru; shard->lruLowPri = &shard->lru; + taosThreadMutexUnlock(&shard->mutex); taosLRUCacheShardSetCapacity(shard, capacity); diff --git a/source/util/src/tpagedbuf.c b/source/util/src/tpagedbuf.c index 94d90104aa..c81888eb95 100644 --- a/source/util/src/tpagedbuf.c +++ b/source/util/src/tpagedbuf.c @@ -534,7 +534,9 @@ void destroyDiskbasedBuf(SDiskbasedBuf* pBuf) { } } - taosRemoveFile(pBuf->path); + if (taosRemoveFile(pBuf->path) < 0) { + uDebug("WARNING tPage remove file failed. path=%s", pBuf->path); + } taosMemoryFreeClear(pBuf->path); size_t n = taosArrayGetSize(pBuf->pIdList); diff --git a/tools/shell/src/shellAuto.c b/tools/shell/src/shellAuto.c index e7dfd45c60..534ecf3c4d 100644 --- a/tools/shell/src/shellAuto.c +++ b/tools/shell/src/shellAuto.c @@ -564,6 +564,7 @@ void parseCommand(SWords* command, bool pattern) { // free SShellCmd void freeCommand(SWords* command) { SWord* item = command->head; + command->head = NULL; // loop while (item) { SWord* tmp = item; @@ -815,7 +816,9 @@ char* matchNextPrefix(STire* tire, char* pre) { match = enumAll(tire); } else { // NOT EMPTY - match = matchPrefix(tire, pre, NULL); + match = (SMatch*)taosMemoryMalloc(sizeof(SMatch)); + memset(match, 0, sizeof(SMatch)); + matchPrefix(tire, pre, match); } // save to lastMatch @@ -828,7 +831,7 @@ char* matchNextPrefix(STire* tire, char* pre) { // check valid if (match == NULL || match->head == NULL) { // no one matched - return false; + return NULL; } if (cursorVar == -1) { diff --git a/tools/shell/src/shellTire.c b/tools/shell/src/shellTire.c index 0628570904..25defbf9a8 100644 --- a/tools/shell/src/shellTire.c +++ b/tools/shell/src/shellTire.c @@ -308,25 +308,21 @@ void matchPrefixFromTree(STire* tire, char* prefix, SMatch* match) { } } -SMatch* matchPrefix(STire* tire, char* prefix, SMatch* match) { - SMatch* rMatch = match; // define return match - if (rMatch == NULL) { - rMatch = (SMatch*)taosMemoryMalloc(sizeof(SMatch)); - memset(rMatch, 0, sizeof(SMatch)); +void matchPrefix(STire* tire, char* prefix, SMatch* match) { + if (match == NULL) { + return; } switch (tire->type) { case TIRE_TREE: - matchPrefixFromTree(tire, prefix, rMatch); + matchPrefixFromTree(tire, prefix, match); break; case TIRE_LIST: - matchPrefixFromList(tire, prefix, rMatch); + matchPrefixFromList(tire, prefix, match); break; default: break; } - - return rMatch; } // get all items from tires tree @@ -362,8 +358,9 @@ void enumFromTree(STire* tire, SMatch* match) { // this branch have data if (c->end) addWordToMatch(match, pre); - else + else { matchPrefix(tire, pre, match); + } } }