From 3ca44498bfd79061c0e535f0b9a3bc7d62bad07b Mon Sep 17 00:00:00 2001 From: Bomin Zhang Date: Fri, 24 Jul 2020 13:57:53 +0800 Subject: [PATCH] TD-905: fix some crash when memory allocation fail --- src/mnode/src/mnodeTable.c | 3 +++ src/query/src/qExecutor.c | 6 ++++-- src/query/src/qUtil.c | 3 +++ src/tsdb/src/tsdbMeta.c | 4 +++- src/tsdb/src/tsdbRead.c | 5 ++++- 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index 12ab58d949..795a4d3621 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -1405,6 +1405,9 @@ static int32_t mnodeSetSchemaFromSuperTable(SSchema *pSchema, SSuperTableObj *pT static int32_t mnodeGetSuperTableMeta(SMnodeMsg *pMsg) { SSuperTableObj *pTable = (SSuperTableObj *)pMsg->pTable; STableMetaMsg *pMeta = rpcMallocCont(sizeof(STableMetaMsg) + sizeof(SSchema) * (TSDB_MAX_TAGS + TSDB_MAX_COLUMNS + 16)); + if (pMeta == NULL) { + return TSDB_CODE_MND_OUT_OF_MEMORY; + } pMeta->uid = htobe64(pTable->uid); pMeta->sversion = htons(pTable->sversion); pMeta->tversion = htons(pTable->tversion); diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 1220c5ca31..8afc2fd87a 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -5913,8 +5913,10 @@ _cleanup_qinfo: tsdbDestroyTableGroup(pTableGroupInfo); _cleanup_query: - taosArrayDestroy(pGroupbyExpr->columnInfo); - tfree(pGroupbyExpr); + if (pGroupbyExpr != NULL) { + taosArrayDestroy(pGroupbyExpr->columnInfo); + free(pGroupbyExpr); + } tfree(pTagCols); for (int32_t i = 0; i < numOfOutput; ++i) { SExprInfo* pExprInfo = &pExprs[i]; diff --git a/src/query/src/qUtil.c b/src/query/src/qUtil.c index be84471493..7b03dd9d94 100644 --- a/src/query/src/qUtil.c +++ b/src/query/src/qUtil.c @@ -41,6 +41,9 @@ int32_t initWindowResInfo(SWindowResInfo *pWindowResInfo, SQueryRuntimeEnv *pRun pWindowResInfo->type = type; _hash_fn_t fn = taosGetDefaultHashFunction(type); pWindowResInfo->hashList = taosHashInit(threshold, fn, false); + if (pWindowResInfo->hashList == NULL) { + return TSDB_CODE_QRY_OUT_OF_MEMORY; + } pWindowResInfo->curIndex = -1; pWindowResInfo->size = 0; diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index b25e734694..d7ed879fa5 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -1215,7 +1215,9 @@ static void *tsdbInsertTableAct(STsdbRepo *pRepo, int8_t act, void *buf, STable static int tsdbRemoveTableFromStore(STsdbRepo *pRepo, STable *pTable) { int tlen = tsdbGetTableEncodeSize(TSDB_DROP_META, pTable); void *buf = tsdbAllocBytes(pRepo, tlen); - ASSERT(buf != NULL); + if (buf == NULL) { + return -1; + } void *pBuf = buf; if (TABLE_TYPE(pTable) == TSDB_SUPER_TABLE) { diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index c82d1f905a..974819d4de 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -175,6 +175,9 @@ static SArray* getDefaultLoadColumns(STsdbQueryHandle* pQueryHandle, bool loadTS TsdbQueryHandleT* tsdbQueryTables(TSDB_REPO_T* tsdb, STsdbQueryCond* pCond, STableGroupInfo* groupList, void* qinfo) { STsdbQueryHandle* pQueryHandle = calloc(1, sizeof(STsdbQueryHandle)); + if (pQueryHandle == NULL) { + goto out_of_memory; + } pQueryHandle->order = pCond->order; pQueryHandle->window = pCond->twindow; pQueryHandle->pTsdb = tsdb; @@ -260,8 +263,8 @@ TsdbQueryHandleT* tsdbQueryTables(TSDB_REPO_T* tsdb, STsdbQueryCond* pCond, STab return (TsdbQueryHandleT) pQueryHandle; out_of_memory: - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; tsdbCleanupQueryHandle(pQueryHandle); + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; return NULL; } -- GitLab