Merge pull request #27477 from taosdata/fix/3.0/TD-31703

fix:[TD-31703] fix memory leak when error occurs in filterMergeGroupUnits
This commit is contained in:
dapan1121 2024-08-27 10:56:28 +08:00 committed by GitHub
commit dc7f56e7f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 12 deletions

View File

@ -464,7 +464,7 @@ struct SFilterInfo {
(colInfo).type = RANGE_TYPE_UNIT; \ (colInfo).type = RANGE_TYPE_UNIT; \
(colInfo).dataType = FILTER_UNIT_DATA_TYPE(u); \ (colInfo).dataType = FILTER_UNIT_DATA_TYPE(u); \
if (taosArrayPush((SArray *)((colInfo).info), &u) == NULL) { \ if (taosArrayPush((SArray *)((colInfo).info), &u) == NULL) { \
FLT_ERR_RET(terrno); \ FLT_ERR_JRET(terrno); \
} \ } \
} while (0) } while (0)
#define FILTER_PUSH_VAR_HASH(colInfo, ha) \ #define FILTER_PUSH_VAR_HASH(colInfo, ha) \
@ -482,7 +482,7 @@ struct SFilterInfo {
do { \ do { \
*(dst) = taosMemoryMalloc(sizeof(uint32_t) * n); \ *(dst) = taosMemoryMalloc(sizeof(uint32_t) * n); \
if (NULL == *(dst)) { \ if (NULL == *(dst)) { \
FLT_ERR_JRET(terrno); \ FLT_ERR_JRET(terrno); \
} \ } \
(void)memcpy(*(dst), src, sizeof(uint32_t) * n); \ (void)memcpy(*(dst), src, sizeof(uint32_t) * n); \
} while (0) } while (0)

View File

@ -2446,8 +2446,7 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx **gRes, int32_t
} }
gRes[gResIdx]->colInfo = taosMemoryCalloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(SFilterColInfo)); gRes[gResIdx]->colInfo = taosMemoryCalloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(SFilterColInfo));
if (gRes[gResIdx]->colInfo == NULL) { if (gRes[gResIdx]->colInfo == NULL) {
filterFreeGroupCtx(gRes[gResIdx]); FLT_ERR_JRET(terrno);
FLT_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
} }
colIdxi = 0; colIdxi = 0;
empty = false; empty = false;
@ -2459,7 +2458,6 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx **gRes, int32_t
if (gRes[gResIdx]->colInfo[cidx].info == NULL) { if (gRes[gResIdx]->colInfo[cidx].info == NULL) {
gRes[gResIdx]->colInfo[cidx].info = (SArray *)taosArrayInit(4, POINTER_BYTES); gRes[gResIdx]->colInfo[cidx].info = (SArray *)taosArrayInit(4, POINTER_BYTES);
if (gRes[gResIdx]->colInfo[cidx].info == NULL) { if (gRes[gResIdx]->colInfo[cidx].info == NULL) {
filterFreeGroupCtx(gRes[gResIdx]);
FLT_ERR_JRET(terrno); FLT_ERR_JRET(terrno);
} }
colIdx[colIdxi++] = cidx; colIdx[colIdxi++] = cidx;
@ -2476,7 +2474,6 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx **gRes, int32_t
if (colIdxi > 1) { if (colIdxi > 1) {
__compar_fn_t cmpFn = getComparFunc(TSDB_DATA_TYPE_USMALLINT, 0); __compar_fn_t cmpFn = getComparFunc(TSDB_DATA_TYPE_USMALLINT, 0);
if (cmpFn == NULL) { if (cmpFn == NULL) {
filterFreeGroupCtx(gRes[gResIdx]);
FLT_ERR_JRET(terrno); FLT_ERR_JRET(terrno);
} }
taosSort(colIdx, colIdxi, sizeof(uint32_t), cmpFn); taosSort(colIdx, colIdxi, sizeof(uint32_t), cmpFn);
@ -2488,12 +2485,7 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx **gRes, int32_t
if (FILTER_NO_MERGE_DATA_TYPE(type)) { if (FILTER_NO_MERGE_DATA_TYPE(type)) {
continue; continue;
} }
SCL_ERR_JRET(filterMergeUnits(info, gRes[gResIdx], colIdx[l], &empty));
code = filterMergeUnits(info, gRes[gResIdx], colIdx[l], &empty);
if (TSDB_CODE_SUCCESS != code) {
filterFreeGroupCtx(gRes[gResIdx]);
SCL_ERR_JRET(code);
}
if (empty) { if (empty) {
break; break;
@ -2519,6 +2511,9 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx **gRes, int32_t
} }
_return: _return:
if (code) {
filterFreeGroupCtx(gRes[gResIdx]);
}
taosMemoryFreeClear(colIdx); taosMemoryFreeClear(colIdx);
FLT_RET(code); FLT_RET(code);
} }