From c170cb4cf916f8a514d83fc866082d66eb53d769 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Tue, 6 Aug 2024 19:05:50 +0800 Subject: [PATCH 1/2] fix(tsdb/cache): return oom with null array init --- source/dnode/vnode/src/tsdb/tsdbCache.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index 8d5fa8b0b3..0e0e055e64 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -1411,6 +1411,9 @@ static int32_t tsdbCacheLoadFromRaw(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArr if (IS_LAST_KEY(idxKey->key)) { if (NULL == lastTmpIndexArray) { lastTmpIndexArray = taosArrayInit(num_keys, sizeof(int32_t)); + if (!lastTmpIndexArray) { + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + } } (void)taosArrayPush(lastTmpIndexArray, &(i)); lastColIds[lastIndex] = idxKey->key.cid; @@ -1419,6 +1422,9 @@ static int32_t tsdbCacheLoadFromRaw(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArr } else { if (NULL == lastrowTmpIndexArray) { lastrowTmpIndexArray = taosArrayInit(num_keys, sizeof(int32_t)); + if (!lastrowTmpIndexArray) { + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + } } (void)taosArrayPush(lastrowTmpIndexArray, &(i)); lastrowColIds[lastrowIndex] = idxKey->key.cid; From 3d29fde68cd073f2e474cfad3e4ede7b2509e62e Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Wed, 7 Aug 2024 08:44:09 +0800 Subject: [PATCH 2/2] destroy non-null array before return --- source/dnode/vnode/src/tsdb/tsdbCache.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index 0e0e055e64..ccad7bac5e 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -1412,6 +1412,8 @@ static int32_t tsdbCacheLoadFromRaw(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArr if (NULL == lastTmpIndexArray) { lastTmpIndexArray = taosArrayInit(num_keys, sizeof(int32_t)); if (!lastTmpIndexArray) { + taosArrayDestroy(lastrowTmpIndexArray); + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); } } @@ -1423,6 +1425,8 @@ static int32_t tsdbCacheLoadFromRaw(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArr if (NULL == lastrowTmpIndexArray) { lastrowTmpIndexArray = taosArrayInit(num_keys, sizeof(int32_t)); if (!lastrowTmpIndexArray) { + taosArrayDestroy(lastTmpIndexArray); + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); } } @@ -1434,6 +1438,11 @@ static int32_t tsdbCacheLoadFromRaw(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArr } pTmpColArray = taosArrayInit(lastIndex + lastrowIndex, sizeof(SLastCol)); + if (!pTmpColArray) { + taosArrayDestroy(lastrowTmpIndexArray); + taosArrayDestroy(lastTmpIndexArray); + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + } if (lastTmpIndexArray != NULL) { (void)mergeLastCid(uid, pTsdb, &lastTmpColArray, pr, lastColIds, lastIndex, lastSlotIds);