From 2062b768db6286653c94803ea7cceb5a580e9980 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Wed, 4 Aug 2021 00:01:13 +0800 Subject: [PATCH] [TD-5694]: fix memory alloc --- src/common/src/tdataformat.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/common/src/tdataformat.c b/src/common/src/tdataformat.c index c3615e64fc..c96c916a01 100644 --- a/src/common/src/tdataformat.c +++ b/src/common/src/tdataformat.c @@ -267,6 +267,7 @@ void dataColAppendVal(SDataCol *pCol, const void *value, int numOfRows, int maxP } bool isNEleNull(SDataCol *pCol, int nEle) { + if(isAllRowsNull(pCol)) return true; for (int i = 0; i < nEle; i++) { if (!isNull(tdGetColDataOfRow(pCol, i), pCol->type)) return false; } @@ -360,6 +361,15 @@ 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; } if (schemaTLen(pSchema) > pCols->maxRowSize) {