提交 e0f0536d 编写于 作者: M Minglei Jin

cache/serialize: nullize pData if zero-length

上级 5349fac9
...@@ -159,7 +159,11 @@ SLastCol *tsdbCacheDeserialize(char const *value) { ...@@ -159,7 +159,11 @@ SLastCol *tsdbCacheDeserialize(char const *value) {
SLastCol *pLastCol = (SLastCol *)value; SLastCol *pLastCol = (SLastCol *)value;
SColVal *pColVal = &pLastCol->colVal; SColVal *pColVal = &pLastCol->colVal;
if (IS_VAR_DATA_TYPE(pColVal->type)) { 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; return pLastCol;
...@@ -177,8 +181,10 @@ void tsdbCacheSerialize(SLastCol *pLastCol, char **value, size_t *size) { ...@@ -177,8 +181,10 @@ void tsdbCacheSerialize(SLastCol *pLastCol, char **value, size_t *size) {
if (IS_VAR_DATA_TYPE(pColVal->type)) { if (IS_VAR_DATA_TYPE(pColVal->type)) {
uint8_t *pVal = pColVal->value.pData; uint8_t *pVal = pColVal->value.pData;
pColVal->value.pData = *value + sizeof(*pLastCol); pColVal->value.pData = *value + sizeof(*pLastCol);
if (pColVal->value.nData) { if (pColVal->value.nData > 0) {
memcpy(pColVal->value.pData, pVal, pColVal->value.nData); memcpy(pColVal->value.pData, pVal, pColVal->value.nData);
} else {
pColVal->value.pData = NULL;
} }
} }
*size = length; *size = length;
......
...@@ -208,7 +208,7 @@ void* tsdbCacherowsReaderClose(void* pReader) { ...@@ -208,7 +208,7 @@ void* tsdbCacherowsReaderClose(void* pReader) {
static void freeItem(void* pItem) { static void freeItem(void* pItem) {
SLastCol* pCol = (SLastCol*)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); taosMemoryFree(pCol->colVal.value.pData);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册