fix: memory leak when alter json tag to NULL

This commit is contained in:
kailixu 2024-03-15 16:29:10 +08:00
parent a5f06114fd
commit d02a125f34
4 changed files with 8 additions and 2 deletions

View File

@ -2820,6 +2820,7 @@ typedef struct {
char* tagName; char* tagName;
int8_t isNull; int8_t isNull;
int8_t tagType; int8_t tagType;
int8_t nullToken;
uint32_t nTagVal; uint32_t nTagVal;
uint8_t* pTagVal; uint8_t* pTagVal;
SArray* pTagArray; SArray* pTagArray;

View File

@ -922,7 +922,8 @@ static int32_t parseTagsClauseImpl(SInsertParseContext* pCxt, SVnodeModifyOpStmt
if (!(pTagVals = taosArrayInit(pCxt->tags.numOfBound, sizeof(STagVal))) || if (!(pTagVals = taosArrayInit(pCxt->tags.numOfBound, sizeof(STagVal))) ||
!(pTagName = taosArrayInit(pCxt->tags.numOfBound, TSDB_COL_NAME_LEN))) { !(pTagName = taosArrayInit(pCxt->tags.numOfBound, TSDB_COL_NAME_LEN))) {
return TSDB_CODE_OUT_OF_MEMORY; code = TSDB_CODE_OUT_OF_MEMORY;
goto _exit;
} }
for (int i = 0; TSDB_CODE_SUCCESS == code && i < pCxt->tags.numOfBound; ++i) { for (int i = 0; TSDB_CODE_SUCCESS == code && i < pCxt->tags.numOfBound; ++i) {
@ -967,6 +968,7 @@ static int32_t parseTagsClauseImpl(SInsertParseContext* pCxt, SVnodeModifyOpStmt
pTag = NULL; pTag = NULL;
} }
_exit:
for (int32_t i = 0; i < TARRAY_SIZE(pTagVals); ++i) { for (int32_t i = 0; i < TARRAY_SIZE(pTagVals); ++i) {
STagVal* p = (STagVal*)TARRAY_GET_ELEM(pTagVals, i); STagVal* p = (STagVal*)TARRAY_GET_ELEM(pTagVals, i);
if (IS_VAR_DATA_TYPE(p->type)) { if (IS_VAR_DATA_TYPE(p->type)) {

View File

@ -10442,6 +10442,9 @@ static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pS
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = parseTagValue(&pCxt->msgBuf, &tagStr, pTableMeta->tableInfo.precision, pSchema, &token, NULL, code = parseTagValue(&pCxt->msgBuf, &tagStr, pTableMeta->tableInfo.precision, pSchema, &token, NULL,
pReq->pTagArray, &pTag); pReq->pTagArray, &pTag);
if (pSchema->type == TSDB_DATA_TYPE_JSON && token.type == TK_NULL && code == TSDB_CODE_SUCCESS) {
pReq->nullToken = true;
}
} }
if (TSDB_CODE_SUCCESS == code && tagStr) { if (TSDB_CODE_SUCCESS == code && tagStr) {
NEXT_VALID_TOKEN(tagStr, token); NEXT_VALID_TOKEN(tagStr, token);
@ -10703,6 +10706,7 @@ static void destoryAlterTbReq(SVAlterTbReq* pReq) {
} }
} }
taosArrayDestroy(pReq->pTagArray); taosArrayDestroy(pReq->pTagArray);
if(pReq->nullToken) tTagFree((STag*)pReq->pTagVal);
} }
static int32_t rewriteAlterTableImpl(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta, static int32_t rewriteAlterTableImpl(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta,

View File

@ -395,7 +395,6 @@ sql alter table $tb set tag tgcol6='1'
sql reset query cache sql reset query cache
sql select * from $mt where tgcol5 = '5' sql select * from $mt where tgcol5 = '5'
print $mt
print select * from $mt where tgcol5 = 5 print select * from $mt where tgcol5 = 5
print $data01 $data02 $data03 $data04 print $data01 $data02 $data03 $data04
if $rows != 1 then if $rows != 1 then