diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index 5a1ddf811d851ffabad7336c61707830d5d21385..1360a272cca8c5a7aa926ecd5af61a11e6fc4a8a 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -159,7 +159,11 @@ SLastCol *tsdbCacheDeserialize(char const *value) { SLastCol *pLastCol = (SLastCol *)value; SColVal *pColVal = &pLastCol->colVal; if (IS_VAR_DATA_TYPE(pColVal->type)) { - pColVal->value.pData = (char *)value + sizeof(*pLastCol); + if (pColVal->value.nData > 0) { + pColVal->value.pData = (char *)value + sizeof(*pLastCol); + } else { + pColVal->value.pData = NULL; + } } return pLastCol; @@ -177,8 +181,10 @@ void tsdbCacheSerialize(SLastCol *pLastCol, char **value, size_t *size) { if (IS_VAR_DATA_TYPE(pColVal->type)) { uint8_t *pVal = pColVal->value.pData; pColVal->value.pData = *value + sizeof(*pLastCol); - if (pColVal->value.nData) { + if (pColVal->value.nData > 0) { memcpy(pColVal->value.pData, pVal, pColVal->value.nData); + } else { + pColVal->value.pData = NULL; } } *size = length; diff --git a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c index 0e03e6e5fb98d319d1bccf2e321f9b2335c03af4..0d47940582a9fed54eee0104746c52965f44c0b8 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c @@ -208,7 +208,7 @@ void* tsdbCacherowsReaderClose(void* pReader) { static void freeItem(void* pItem) { SLastCol* pCol = (SLastCol*)pItem; - if (IS_VAR_DATA_TYPE(pCol->colVal.type)) { + if (IS_VAR_DATA_TYPE(pCol->colVal.type) && pCol->colVal.value.pData) { taosMemoryFree(pCol->colVal.value.pData); } }