enh: memory malloc return
This commit is contained in:
parent
8221b2d582
commit
6cb94f69f2
|
@ -360,6 +360,12 @@ static int32_t vmOpenVnodes(SVnodeMgmt *pMgmt) {
|
||||||
int32_t vnodesPerThread = numOfVnodes / threadNum + 1;
|
int32_t vnodesPerThread = numOfVnodes / threadNum + 1;
|
||||||
|
|
||||||
SVnodeThread *threads = taosMemoryCalloc(threadNum, sizeof(SVnodeThread));
|
SVnodeThread *threads = taosMemoryCalloc(threadNum, sizeof(SVnodeThread));
|
||||||
|
if (threads == NULL) {
|
||||||
|
dError("failed to allocate memory for threads since %s", terrstr());
|
||||||
|
taosMemoryFree(pCfgs);
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
|
|
||||||
for (int32_t t = 0; t < threadNum; ++t) {
|
for (int32_t t = 0; t < threadNum; ++t) {
|
||||||
threads[t].threadIndex = t;
|
threads[t].threadIndex = t;
|
||||||
threads[t].pMgmt = pMgmt;
|
threads[t].pMgmt = pMgmt;
|
||||||
|
|
|
@ -1036,36 +1036,6 @@ const void *metaGetTableTagVal(const void *pTag, int16_t type, STagVal *val) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TAG_FILTER_DEBUG
|
|
||||||
if (IS_VAR_DATA_TYPE(val->type)) {
|
|
||||||
char *buf = taosMemoryCalloc(val->nData + 1, 1);
|
|
||||||
memcpy(buf, val->pData, val->nData);
|
|
||||||
metaDebug("metaTag table val varchar index:%d cid:%d type:%d value:%s", 1, val->cid, val->type, buf);
|
|
||||||
taosMemoryFree(buf);
|
|
||||||
} else {
|
|
||||||
double dval = 0;
|
|
||||||
GET_TYPED_DATA(dval, double, val->type, &val->i64);
|
|
||||||
metaDebug("metaTag table val number index:%d cid:%d type:%d value:%f", 1, val->cid, val->type, dval);
|
|
||||||
}
|
|
||||||
|
|
||||||
SArray *pTagVals = NULL;
|
|
||||||
tTagToValArray((STag *)pTag, &pTagVals);
|
|
||||||
for (int i = 0; i < taosArrayGetSize(pTagVals); i++) {
|
|
||||||
STagVal *pTagVal = (STagVal *)taosArrayGet(pTagVals, i);
|
|
||||||
|
|
||||||
if (IS_VAR_DATA_TYPE(pTagVal->type)) {
|
|
||||||
char *buf = taosMemoryCalloc(pTagVal->nData + 1, 1);
|
|
||||||
memcpy(buf, pTagVal->pData, pTagVal->nData);
|
|
||||||
metaDebug("metaTag table varchar index:%d cid:%d type:%d value:%s", i, pTagVal->cid, pTagVal->type, buf);
|
|
||||||
taosMemoryFree(buf);
|
|
||||||
} else {
|
|
||||||
double dval = 0;
|
|
||||||
GET_TYPED_DATA(dval, double, pTagVal->type, &pTagVal->i64);
|
|
||||||
metaDebug("metaTag table number index:%d cid:%d type:%d value:%f", i, pTagVal->cid, pTagVal->type, dval);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1088,6 +1058,9 @@ int32_t metaFilterCreateTime(void *pVnode, SMetaFltParam *arg, SArray *pUids) {
|
||||||
|
|
||||||
SIdxCursor *pCursor = NULL;
|
SIdxCursor *pCursor = NULL;
|
||||||
pCursor = (SIdxCursor *)taosMemoryCalloc(1, sizeof(SIdxCursor));
|
pCursor = (SIdxCursor *)taosMemoryCalloc(1, sizeof(SIdxCursor));
|
||||||
|
if (pCursor == NULL) {
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
pCursor->pMeta = pMeta;
|
pCursor->pMeta = pMeta;
|
||||||
pCursor->suid = param->suid;
|
pCursor->suid = param->suid;
|
||||||
pCursor->cid = param->cid;
|
pCursor->cid = param->cid;
|
||||||
|
@ -1160,6 +1133,9 @@ int32_t metaFilterTableName(void *pVnode, SMetaFltParam *arg, SArray *pUids) {
|
||||||
|
|
||||||
SIdxCursor *pCursor = NULL;
|
SIdxCursor *pCursor = NULL;
|
||||||
pCursor = (SIdxCursor *)taosMemoryCalloc(1, sizeof(SIdxCursor));
|
pCursor = (SIdxCursor *)taosMemoryCalloc(1, sizeof(SIdxCursor));
|
||||||
|
if (pCursor == NULL) {
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
pCursor->pMeta = pMeta;
|
pCursor->pMeta = pMeta;
|
||||||
pCursor->suid = param->suid;
|
pCursor->suid = param->suid;
|
||||||
pCursor->cid = param->cid;
|
pCursor->cid = param->cid;
|
||||||
|
@ -1235,6 +1211,9 @@ int32_t metaFilterTtl(void *pVnode, SMetaFltParam *arg, SArray *pUids) {
|
||||||
|
|
||||||
SIdxCursor *pCursor = NULL;
|
SIdxCursor *pCursor = NULL;
|
||||||
pCursor = (SIdxCursor *)taosMemoryCalloc(1, sizeof(SIdxCursor));
|
pCursor = (SIdxCursor *)taosMemoryCalloc(1, sizeof(SIdxCursor));
|
||||||
|
if (pCursor == NULL) {
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
pCursor->pMeta = pMeta;
|
pCursor->pMeta = pMeta;
|
||||||
pCursor->suid = param->suid;
|
pCursor->suid = param->suid;
|
||||||
pCursor->cid = param->cid;
|
pCursor->cid = param->cid;
|
||||||
|
|
|
@ -89,12 +89,15 @@ static void metaGetEntryInfo(const SMetaEntry *pEntry, SMetaInfo *pInfo) {
|
||||||
|
|
||||||
static int metaUpdateMetaRsp(tb_uid_t uid, char *tbName, SSchemaWrapper *pSchema, STableMetaRsp *pMetaRsp) {
|
static int metaUpdateMetaRsp(tb_uid_t uid, char *tbName, SSchemaWrapper *pSchema, STableMetaRsp *pMetaRsp) {
|
||||||
pMetaRsp->pSchemas = taosMemoryMalloc(pSchema->nCols * sizeof(SSchema));
|
pMetaRsp->pSchemas = taosMemoryMalloc(pSchema->nCols * sizeof(SSchema));
|
||||||
|
|
||||||
if (NULL == pMetaRsp->pSchemas) {
|
if (NULL == pMetaRsp->pSchemas) {
|
||||||
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
pMetaRsp->pSchemaExt = taosMemoryMalloc(pSchema->nCols * sizeof(SSchemaExt));
|
pMetaRsp->pSchemaExt = taosMemoryMalloc(pSchema->nCols * sizeof(SSchemaExt));
|
||||||
|
if (pMetaRsp->pSchemaExt == NULL) {
|
||||||
|
taosMemoryFree(pMetaRsp->pSchemas);
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
|
|
||||||
tstrncpy(pMetaRsp->tbName, tbName, TSDB_TABLE_NAME_LEN);
|
tstrncpy(pMetaRsp->tbName, tbName, TSDB_TABLE_NAME_LEN);
|
||||||
pMetaRsp->numOfColumns = pSchema->nCols;
|
pMetaRsp->numOfColumns = pSchema->nCols;
|
||||||
|
@ -1558,7 +1561,11 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
||||||
|
|
||||||
// get table entry
|
// get table entry
|
||||||
SDecoder dc = {0};
|
SDecoder dc = {0};
|
||||||
entry.pBuf = taosMemoryMalloc(nData);
|
if ((entry.pBuf = taosMemoryMalloc(nData)) == NULL) {
|
||||||
|
(void)tdbTbcClose(pUidIdxc);
|
||||||
|
(void)tdbTbcClose(pTbDbc);
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
memcpy(entry.pBuf, pData, nData);
|
memcpy(entry.pBuf, pData, nData);
|
||||||
tDecoderInit(&dc, entry.pBuf, nData);
|
tDecoderInit(&dc, entry.pBuf, nData);
|
||||||
ret = metaDecodeEntry(&dc, &entry);
|
ret = metaDecodeEntry(&dc, &entry);
|
||||||
|
@ -1625,6 +1632,9 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
||||||
pSchema->version++;
|
pSchema->version++;
|
||||||
pSchema->nCols++;
|
pSchema->nCols++;
|
||||||
pNewSchema = taosMemoryMalloc(sizeof(SSchema) * pSchema->nCols);
|
pNewSchema = taosMemoryMalloc(sizeof(SSchema) * pSchema->nCols);
|
||||||
|
if (pNewSchema == NULL) {
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
memcpy(pNewSchema, pSchema->pSchema, sizeof(SSchema) * (pSchema->nCols - 1));
|
memcpy(pNewSchema, pSchema->pSchema, sizeof(SSchema) * (pSchema->nCols - 1));
|
||||||
pSchema->pSchema = pNewSchema;
|
pSchema->pSchema = pNewSchema;
|
||||||
pSchema->pSchema[entry.ntbEntry.schemaRow.nCols - 1].bytes = pAlterTbReq->bytes;
|
pSchema->pSchema[entry.ntbEntry.schemaRow.nCols - 1].bytes = pAlterTbReq->bytes;
|
||||||
|
@ -1832,7 +1842,11 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
|
||||||
|
|
||||||
(void)tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData);
|
(void)tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData);
|
||||||
|
|
||||||
ctbEntry.pBuf = taosMemoryMalloc(nData);
|
if ((ctbEntry.pBuf = taosMemoryMalloc(nData)) == NULL) {
|
||||||
|
(void)tdbTbcClose(pUidIdxc);
|
||||||
|
(void)tdbTbcClose(pTbDbc);
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
memcpy(ctbEntry.pBuf, pData, nData);
|
memcpy(ctbEntry.pBuf, pData, nData);
|
||||||
tDecoderInit(&dc1, ctbEntry.pBuf, nData);
|
tDecoderInit(&dc1, ctbEntry.pBuf, nData);
|
||||||
(void)metaDecodeEntry(&dc1, &ctbEntry);
|
(void)metaDecodeEntry(&dc1, &ctbEntry);
|
||||||
|
@ -2019,7 +2033,11 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p
|
||||||
|
|
||||||
// get table entry
|
// get table entry
|
||||||
SDecoder dc = {0};
|
SDecoder dc = {0};
|
||||||
entry.pBuf = taosMemoryMalloc(nData);
|
if ((entry.pBuf = taosMemoryMalloc(nData)) == NULL) {
|
||||||
|
(void)tdbTbcClose(pUidIdxc);
|
||||||
|
(void)tdbTbcClose(pTbDbc);
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
memcpy(entry.pBuf, pData, nData);
|
memcpy(entry.pBuf, pData, nData);
|
||||||
tDecoderInit(&dc, entry.pBuf, nData);
|
tDecoderInit(&dc, entry.pBuf, nData);
|
||||||
ret = metaDecodeEntry(&dc, &entry);
|
ret = metaDecodeEntry(&dc, &entry);
|
||||||
|
|
|
@ -1412,6 +1412,10 @@ static int32_t vnodeProcessDropTbReq(SVnode *pVnode, int64_t ver, void *pReq, in
|
||||||
|
|
||||||
if (tsEnableAuditCreateTable) {
|
if (tsEnableAuditCreateTable) {
|
||||||
char *str = taosMemoryCalloc(1, TSDB_TABLE_FNAME_LEN);
|
char *str = taosMemoryCalloc(1, TSDB_TABLE_FNAME_LEN);
|
||||||
|
if (str == NULL) {
|
||||||
|
pRsp->code = terrno;
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
strcpy(str, pDropTbReq->name);
|
strcpy(str, pDropTbReq->name);
|
||||||
if (taosArrayPush(tbNames, &str) == NULL) {
|
if (taosArrayPush(tbNames, &str) == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
|
|
@ -597,7 +597,9 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
|
||||||
if (sIdx + i < TDB_PAGE_TOTAL_CELLS(pParent)) {
|
if (sIdx + i < TDB_PAGE_TOTAL_CELLS(pParent)) {
|
||||||
pCell = tdbPageGetCell(pParent, sIdx + i);
|
pCell = tdbPageGetCell(pParent, sIdx + i);
|
||||||
szDivCell[i] = tdbBtreeCellSize(pParent, pCell, 0, NULL, NULL);
|
szDivCell[i] = tdbBtreeCellSize(pParent, pCell, 0, NULL, NULL);
|
||||||
pDivCell[i] = tdbOsMalloc(szDivCell[i]);
|
if ((pDivCell[i] = tdbOsMalloc(szDivCell[i])) == NULL) {
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
memcpy(pDivCell[i], pCell, szDivCell[i]);
|
memcpy(pDivCell[i], pCell, szDivCell[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -832,6 +834,9 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
|
||||||
|
|
||||||
// TODO: pCell here may be inserted as an overflow cell, handle it
|
// TODO: pCell here may be inserted as an overflow cell, handle it
|
||||||
SCell *pNewCell = tdbOsMalloc(cd.kLen + 9);
|
SCell *pNewCell = tdbOsMalloc(cd.kLen + 9);
|
||||||
|
if (pNewCell == NULL) {
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
int szNewCell;
|
int szNewCell;
|
||||||
SPgno pgno;
|
SPgno pgno;
|
||||||
pgno = TDB_PAGE_PGNO(pNews[iNew]);
|
pgno = TDB_PAGE_PGNO(pNews[iNew]);
|
||||||
|
@ -2201,7 +2206,10 @@ int tdbBtcDelete(SBTC *pBtc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the cell with new key
|
// update the cell with new key
|
||||||
pCell = tdbOsMalloc(nKey + 9);
|
if ((pCell = tdbOsMalloc(nKey + 9)) == NULL) {
|
||||||
|
tdbError("tdb/btc-delete: malloc failed.");
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
(void)tdbBtreeEncodeCell(pPage, pKey, nKey, &pgno, sizeof(pgno), pCell, &szCell, pBtc->pTxn, pBtc->pBt);
|
(void)tdbBtreeEncodeCell(pPage, pKey, nKey, &pgno, sizeof(pgno), pCell, &szCell, pBtc->pTxn, pBtc->pBt);
|
||||||
|
|
||||||
ret = tdbPageUpdateCell(pPage, idx, pCell, szCell, pBtc->pTxn, pBtc->pBt);
|
ret = tdbPageUpdateCell(pPage, idx, pCell, szCell, pBtc->pTxn, pBtc->pBt);
|
||||||
|
|
|
@ -184,6 +184,10 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl
|
||||||
|
|
||||||
// TODO: here has memory leak
|
// TODO: here has memory leak
|
||||||
pNewCell = (SCell *)tdbOsMalloc(szCell);
|
pNewCell = (SCell *)tdbOsMalloc(szCell);
|
||||||
|
if (pNewCell == NULL) {
|
||||||
|
tdbError("tdb/page-insert-cell: malloc failed.");
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
memcpy(pNewCell, pCell, szCell);
|
memcpy(pNewCell, pCell, szCell);
|
||||||
|
|
||||||
tdbTrace("tdbPage/insert/new ovfl cell: %p/%p", pNewCell, pPage);
|
tdbTrace("tdbPage/insert/new ovfl cell: %p/%p", pNewCell, pPage);
|
||||||
|
|
Loading…
Reference in New Issue