From 42db901a22ac8d438adc4ae680d29c2d736b6d4b Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Wed, 4 Aug 2021 00:51:35 +0800 Subject: [PATCH] [TD-5694]: fix --- src/common/inc/tdataformat.h | 2 +- src/common/src/tdataformat.c | 20 +++++--------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/common/inc/tdataformat.h b/src/common/inc/tdataformat.h index 53e77430d3..fb6bab0cf2 100644 --- a/src/common/inc/tdataformat.h +++ b/src/common/inc/tdataformat.h @@ -325,7 +325,7 @@ typedef struct SDataCol { #define isAllRowsNull(pCol) ((pCol)->len == 0) static FORCE_INLINE void dataColReset(SDataCol *pDataCol) { pDataCol->len = 0; } -void tdAllocMemForCol(SDataCol *pCol, int maxPoints); +int tdAllocMemForCol(SDataCol *pCol, int maxPoints); void dataColInit(SDataCol *pDataCol, STColumn *pCol, int maxPoints); void dataColAppendVal(SDataCol *pCol, const void *value, int numOfRows, int maxPoints); diff --git a/src/common/src/tdataformat.c b/src/common/src/tdataformat.c index 16c96bb16f..44a138cec4 100644 --- a/src/common/src/tdataformat.c +++ b/src/common/src/tdataformat.c @@ -22,7 +22,7 @@ static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, int limit1, SDataCols *src2, int *iter2, int limit2, int tRows, bool forceSetNull); -void tdAllocMemForCol(SDataCol *pCol, int maxPoints) { +int tdAllocMemForCol(SDataCol *pCol, int maxPoints) { int spaceNeeded = pCol->bytes * maxPoints; if(IS_VAR_DATA_TYPE(pCol->type)) { spaceNeeded += sizeof(VarDataOffsetT) * maxPoints; @@ -30,8 +30,10 @@ void tdAllocMemForCol(SDataCol *pCol, int maxPoints) { if(pCol->spaceSize < spaceNeeded) { void* ptr = realloc(pCol->pData, spaceNeeded); if(ptr == NULL) { + ASSERT(false); uDebug("malloc failure, size:%" PRId64 " failed, reason:%s", (int64_t)pCol->spaceSize, strerror(errno)); + return -1; } else { pCol->pData = ptr; pCol->spaceSize = spaceNeeded; @@ -40,6 +42,7 @@ void tdAllocMemForCol(SDataCol *pCol, int maxPoints) { } } } + return 0; } /** @@ -361,20 +364,6 @@ int tdInitDataCols(SDataCols *pCols, STSchema *pSchema) { pCols->cols[i].dataOff = NULL; pCols->cols[i].spaceSize = 0; } - } else if(schemaNCols(pSchema) < oldMaxCols){ - //TODO: this handling should not exist, for alloc will handle it nicely - for(i = schemaNCols(pSchema); i < oldMaxCols; i++) { - tfree(pCols->cols[i].pData); - pCols->cols[i].spaceSize = 0; - } - pCols->maxCols = schemaNCols(pSchema); - pCols->cols = (SDataCol *)realloc(pCols->cols, sizeof(SDataCol) * pCols->maxCols); - if (pCols->cols == NULL) return -1; - } - for(i = 0; i < pCols->maxCols; i++) { - tfree(pCols->cols[i].pData); - pCols->cols[i].dataOff = NULL; - pCols->cols[i].spaceSize = 0; } if (schemaTLen(pSchema) > pCols->maxRowSize) { @@ -386,6 +375,7 @@ int tdInitDataCols(SDataCols *pCols, STSchema *pSchema) { for (i = 0; i < schemaNCols(pSchema); i++) { dataColInit(pCols->cols + i, schemaColAt(pSchema, i), pCols->maxPoints); + tdAllocMemForCol(pCols->cols + i, pCols->maxPoints); } return 0; -- GitLab