From 3e5aec6742beba5bd0fe1fc70478236745d4084e Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sun, 25 Apr 2021 12:00:19 +0800 Subject: [PATCH] [td-225]fix memory leak. --- src/client/src/tscServer.c | 2 +- src/query/inc/qSqlparser.h | 7 +------ src/query/inc/sql.y | 2 ++ src/query/src/qSqlParser.c | 4 ++-- src/query/src/sql.c | 6 ++++++ 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index c9cb161a4b..4156bc7649 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -2155,7 +2155,7 @@ int tscProcessShowRsp(SSqlObj *pSql) { uint64_t uid = pTableMetaInfo->pTableMeta->id.uid; for (int16_t i = 0; i < pMetaMsg->numOfColumns; ++i, ++pSchema) { index.columnIndex = i; - tscColumnListInsert(pQueryInfo->colList, i, uid, &pSchema[i]); + tscColumnListInsert(pQueryInfo->colList, i, uid, pSchema); TAOS_FIELD f = tscCreateField(pSchema->type, pSchema->name, pSchema->bytes); SInternalField* pInfo = tscFieldInfoAppend(pFieldInfo, &f); diff --git a/src/query/inc/qSqlparser.h b/src/query/inc/qSqlparser.h index 1fb92008fd..63dc7b3761 100644 --- a/src/query/inc/qSqlparser.h +++ b/src/query/inc/qSqlparser.h @@ -106,11 +106,6 @@ typedef struct STableNamePair { SStrToken aliasName; } STableNamePair; -//typedef struct SSubclauseInfo { // "UNION" multiple select sub-clause -// SSqlNode **pClause; -// int32_t numOfClause; -//} SSubclauseInfo; - typedef struct SRelationInfo { int32_t type; // nested query|table name list SArray *list; // SArray|SArray @@ -253,7 +248,7 @@ SArray *tVariantListAppendToken(SArray *pList, SStrToken *pAliasToken, uint8_t s SRelationInfo *setTableNameList(SRelationInfo* pFromInfo, SStrToken *pName, SStrToken* pAlias); SRelationInfo *setSubquery(SRelationInfo* pFromInfo, SArray* pSqlNode); -void *destroyFromInfo(SRelationInfo* pFromInfo); +void *destroyRelationInfo(SRelationInfo* pFromInfo); // sql expr leaf node tSqlExpr *tSqlExprCreateIdValue(SStrToken *pToken, int32_t optrType); diff --git a/src/query/inc/sql.y b/src/query/inc/sql.y index b4a8ec97f8..8ca0dee2d6 100644 --- a/src/query/inc/sql.y +++ b/src/query/inc/sql.y @@ -506,10 +506,12 @@ distinct(X) ::= . { X.n = 0;} // A complete FROM clause. %type from {SRelationInfo*} +%destructor from {destroyRelationInfo($$);} from(A) ::= FROM tablelist(X). {A = X;} from(A) ::= FROM LP union(Y) RP. {A = setSubquery(NULL, Y);} %type tablelist {SRelationInfo*} +%destructor tablelist {destroyRelationInfo($$);} tablelist(A) ::= ids(X) cpxName(Y). { X.n += Y.n; A = setTableNameList(NULL, &X, NULL); diff --git a/src/query/src/qSqlParser.c b/src/query/src/qSqlParser.c index f8f5aafbd8..0cb832f358 100644 --- a/src/query/src/qSqlParser.c +++ b/src/query/src/qSqlParser.c @@ -552,7 +552,7 @@ SRelationInfo* setSubquery(SRelationInfo* pRelationInfo, SArray* pList) { return pRelationInfo; } -void* destroyFromInfo(SRelationInfo* pRelationInfo) { +void* destroyRelationInfo(SRelationInfo* pRelationInfo) { if (pRelationInfo == NULL) { return NULL; } @@ -799,7 +799,7 @@ void destroySqlNode(SSqlNode *pSqlNode) { taosArrayDestroyEx(pSqlNode->pGroupby, freeVariant); pSqlNode->pGroupby = NULL; - pSqlNode->from = destroyFromInfo(pSqlNode->from); + pSqlNode->from = destroyRelationInfo(pSqlNode->from); taosArrayDestroyEx(pSqlNode->fillType, freeVariant); pSqlNode->fillType = NULL; diff --git a/src/query/src/sql.c b/src/query/src/sql.c index a4bc860201..a283a8b916 100644 --- a/src/query/src/sql.c +++ b/src/query/src/sql.c @@ -1433,6 +1433,12 @@ destroySqlNode((yypminor->yy116)); case 261: /* exprlist */ { tSqlExprListDestroy((yypminor->yy159)); +} + break; + case 238: /* from */ + case 254: /* tablelist */ +{ +destroyRelationInfo((yypminor->yy236)); } break; case 239: /* where_opt */ -- GitLab