fix mem leak possible

This commit is contained in:
Yihao Deng 2024-08-30 07:13:56 +00:00
parent 2b11222c06
commit a1db09a360
1 changed files with 20 additions and 8 deletions

View File

@ -661,12 +661,16 @@ int32_t idxFlushCacheToTFile(SIndex* sIdx, void* cache, bool quit) {
} }
SArray* result = taosArrayInit(1024, sizeof(void*)); SArray* result = taosArrayInit(1024, sizeof(void*));
if (result == NULL) {
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception);
}
bool cn = cacheIter ? cacheIter->next(cacheIter) : false; bool cn = cacheIter ? cacheIter->next(cacheIter) : false;
bool tn = tfileIter ? tfileIter->next(tfileIter) : false; bool tn = tfileIter ? tfileIter->next(tfileIter) : false;
SIdxTRslt* tr = idxTRsltCreate(); SIdxTRslt* tr = idxTRsltCreate();
if (tr == NULL) { if (tr == NULL) {
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception);
} }
while (cn == true || tn == true) { while (cn == true || tn == true) {
IterateValue* cv = (cn == true) ? cacheIter->getValue(cacheIter) : NULL; IterateValue* cv = (cn == true) ? cacheIter->getValue(cacheIter) : NULL;
@ -682,33 +686,41 @@ int32_t idxFlushCacheToTFile(SIndex* sIdx, void* cache, bool quit) {
} }
if (comp == 0) { if (comp == 0) {
code = idxMergeCacheAndTFile(result, cv, tv, tr); code = idxMergeCacheAndTFile(result, cv, tv, tr);
if (code != 0) return code; if (code != 0) {
TAOS_CHECK_GOTO(code, NULL, _exception);
}
cn = cacheIter->next(cacheIter); cn = cacheIter->next(cacheIter);
tn = tfileIter->next(tfileIter); tn = tfileIter->next(tfileIter);
} else if (comp < 0) { } else if (comp < 0) {
code = idxMergeCacheAndTFile(result, cv, NULL, tr); code = idxMergeCacheAndTFile(result, cv, NULL, tr);
if (code != 0) return code; if (code != 0) {
TAOS_CHECK_GOTO(code, NULL, _exception);
}
cn = cacheIter->next(cacheIter); cn = cacheIter->next(cacheIter);
} else { } else {
code = idxMergeCacheAndTFile(result, NULL, tv, tr); code = idxMergeCacheAndTFile(result, NULL, tv, tr);
if (code != 0) return code; if (code != 0) {
TAOS_CHECK_GOTO(code, NULL, _exception);
}
tn = tfileIter->next(tfileIter); tn = tfileIter->next(tfileIter);
} }
} }
if ((code = idxMayMergeTempToFinalRslt(result, NULL, tr)) != 0) { if ((code = idxMayMergeTempToFinalRslt(result, NULL, tr)) != 0) {
idxTRsltDestroy(tr); idxTRsltDestroy(tr);
return code; TAOS_CHECK_GOTO(code, NULL, _exception);
} }
idxTRsltDestroy(tr); idxTRsltDestroy(tr);
int ret = idxGenTFile(sIdx, pCache, result); code = idxGenTFile(sIdx, pCache, result);
if (ret != 0) { if (code != 0) {
indexError("failed to merge"); indexError("failed to merge since %s", tstrerror(code));
} else { } else {
int64_t cost = taosGetTimestampUs() - st; int64_t cost = taosGetTimestampUs() - st;
indexInfo("success to merge , time cost: %" PRId64 "ms", cost / 1000); indexInfo("success to merge , time cost: %" PRId64 "ms", cost / 1000);
} }
_exception:
idxDestroyFinalRslt(result); idxDestroyFinalRslt(result);
idxCacheDestroyImm(pCache); idxCacheDestroyImm(pCache);
@ -725,7 +737,7 @@ int32_t idxFlushCacheToTFile(SIndex* sIdx, void* cache, bool quit) {
} }
idxReleaseRef(sIdx->refId); idxReleaseRef(sIdx->refId);
return ret; return code;
} }
void iterateValueDestroy(IterateValue* value, bool destroy) { void iterateValueDestroy(IterateValue* value, bool destroy) {
if (destroy) { if (destroy) {