Merge pull request #27948 from taosdata/enh/TD-32144-3.0
enh: check memory allocation
This commit is contained in:
commit
80152c1e48
|
@ -49,7 +49,7 @@ int32_t toUInteger(const char *z, int32_t n, int32_t base, uint64_t *value);
|
|||
*/
|
||||
int32_t toIntegerPure(const char *z, int32_t n, int32_t base, int64_t *value);
|
||||
|
||||
void taosVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uint32_t type);
|
||||
int32_t taosVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uint32_t type);
|
||||
|
||||
void taosVariantDestroy(SVariant *pV);
|
||||
|
||||
|
|
|
@ -143,7 +143,7 @@ bool tNameIsValid(const SName* name) {
|
|||
|
||||
SName* tNameDup(const SName* name) {
|
||||
SName* p = taosMemoryMalloc(sizeof(SName));
|
||||
memcpy(p, name, sizeof(SName));
|
||||
if (p) TAOS_MEMCPY(p, name, sizeof(SName));
|
||||
return p;
|
||||
}
|
||||
|
||||
|
|
|
@ -368,7 +368,7 @@ int32_t toUInteger(const char *z, int32_t n, int32_t base, uint64_t *value) {
|
|||
* @param len
|
||||
* @param type
|
||||
*/
|
||||
void taosVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uint32_t type) {
|
||||
int32_t taosVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uint32_t type) {
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
case TSDB_DATA_TYPE_TINYINT: {
|
||||
|
@ -426,6 +426,7 @@ void taosVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uin
|
|||
size_t lenInwchar = len / TSDB_NCHAR_SIZE;
|
||||
|
||||
pVar->ucs4 = taosMemoryCalloc(1, (lenInwchar + 1) * TSDB_NCHAR_SIZE);
|
||||
if(!pVar->ucs4) return terrno;
|
||||
(void)memcpy(pVar->ucs4, pz, lenInwchar * TSDB_NCHAR_SIZE);
|
||||
pVar->nLen = (int32_t)len;
|
||||
|
||||
|
@ -446,6 +447,7 @@ void taosVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uin
|
|||
}
|
||||
|
||||
pVar->nType = type;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void taosVariantDestroy(SVariant *pVar) {
|
||||
|
|
|
@ -846,6 +846,7 @@ static int32_t mndRetrieveConns(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
|
|||
if (pShow->pIter == NULL) {
|
||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||
pShow->pIter = taosCacheCreateIter(pMgmt->connCache);
|
||||
if (!pShow->pIter) return terrno;
|
||||
}
|
||||
|
||||
while (numOfRows < rows) {
|
||||
|
@ -1005,6 +1006,7 @@ static int32_t mndRetrieveQueries(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p
|
|||
if (pShow->pIter == NULL) {
|
||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||
pShow->pIter = taosCacheCreateIter(pMgmt->connCache);
|
||||
if (!pShow->pIter) return terrno;
|
||||
}
|
||||
|
||||
// means fetched some data last time for this conn
|
||||
|
@ -1042,6 +1044,7 @@ static int32_t mndRetrieveApps(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlo
|
|||
if (pShow->pIter == NULL) {
|
||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||
pShow->pIter = taosCacheCreateIter(pMgmt->appCache);
|
||||
if (!pShow->pIter) return terrno;
|
||||
}
|
||||
|
||||
while (numOfRows < rows) {
|
||||
|
|
|
@ -3902,8 +3902,7 @@ int32_t doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSD
|
|||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
SVariant val = {0};
|
||||
// TODO(smj) : this func need err code
|
||||
taosVariantCreateFromBinary(&val, pData, tDataTypes[type].bytes, type);
|
||||
TAOS_CHECK_RETURN(taosVariantCreateFromBinary(&val, pData, tDataTypes[type].bytes, type));
|
||||
|
||||
STopBotResItem* pItems = pRes->pItems;
|
||||
|
||||
|
|
|
@ -380,6 +380,14 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInMs, bool extendLi
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pCacheObj->name = taosStrdup(cacheName);
|
||||
if (pCacheObj->name == NULL) {
|
||||
taosMemoryFreeClear(pCacheObj->pEntryList);
|
||||
taosMemoryFree(pCacheObj);
|
||||
uError("failed to allocate memory, reason:%s", terrstr());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// set free cache node callback function
|
||||
pCacheObj->hashFp = taosGetDefaultHashFunction(keyType);
|
||||
pCacheObj->freeFp = fn;
|
||||
|
@ -389,13 +397,13 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInMs, bool extendLi
|
|||
|
||||
if (__trashcan_lock_init(pCacheObj) != 0) {
|
||||
taosMemoryFreeClear(pCacheObj->pEntryList);
|
||||
taosMemoryFreeClear(pCacheObj->name);
|
||||
taosMemoryFree(pCacheObj);
|
||||
|
||||
uError("failed to init lock, reason:%s", strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pCacheObj->name = taosStrdup(cacheName);
|
||||
(void)doRegisterCacheObj(pCacheObj);
|
||||
return pCacheObj;
|
||||
}
|
||||
|
@ -746,8 +754,13 @@ void taosAddToTrashcan(SCacheObj *pCacheObj, SCacheNode *pNode) {
|
|||
return;
|
||||
}
|
||||
|
||||
__trashcan_wr_lock(pCacheObj);
|
||||
STrashElem *pElem = taosMemoryCalloc(1, sizeof(STrashElem));
|
||||
if (!pElem) {
|
||||
uError("cache:%s key:%p, %p move to trashcan failed since %s, numOfElem in trashcan:%d", pCacheObj->name,
|
||||
pNode->key, pNode->data, terrstr(), pCacheObj->numOfElemsInTrash);
|
||||
return;
|
||||
}
|
||||
__trashcan_wr_lock(pCacheObj);
|
||||
pElem->pData = pNode;
|
||||
pElem->prev = NULL;
|
||||
pElem->next = NULL;
|
||||
|
@ -928,9 +941,11 @@ size_t taosCacheGetNumOfObj(const SCacheObj *pCacheObj) { return pCacheObj->numO
|
|||
|
||||
SCacheIter *taosCacheCreateIter(const SCacheObj *pCacheObj) {
|
||||
SCacheIter *pIter = taosMemoryCalloc(1, sizeof(SCacheIter));
|
||||
pIter->pCacheObj = (SCacheObj *)pCacheObj;
|
||||
pIter->entryIndex = -1;
|
||||
pIter->index = -1;
|
||||
if (pIter) {
|
||||
pIter->pCacheObj = (SCacheObj *)pCacheObj;
|
||||
pIter->entryIndex = -1;
|
||||
pIter->index = -1;
|
||||
}
|
||||
return pIter;
|
||||
}
|
||||
|
||||
|
|
|
@ -426,7 +426,12 @@ int32_t cfgCheckRangeForDynUpdate(SConfig *pCfg, const char *name, const char *p
|
|||
switch (pItem->dtype) {
|
||||
case CFG_DTYPE_STRING: {
|
||||
if (strcasecmp(name, "slowLogScope") == 0) {
|
||||
char *tmp = taosStrdup(pVal);
|
||||
char *tmp = taosStrdup(pVal);
|
||||
if (!tmp) {
|
||||
cfgUnLock(pCfg);
|
||||
uError("failed to config:%s since %s", name, terrstr());
|
||||
TAOS_RETURN(terrno);
|
||||
}
|
||||
int32_t scope = 0;
|
||||
int32_t code = taosSetSlowLogScope(tmp, &scope);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
|
|
|
@ -651,7 +651,8 @@ void taosPrintLongString(const char *flags, int32_t level, int32_t dflag, const
|
|||
if (!osLogSpaceSufficient()) return;
|
||||
if (!(dflag & DEBUG_FILE) && !(dflag & DEBUG_SCREEN)) return;
|
||||
|
||||
char *buffer = taosMemoryMalloc(LOG_MAX_LINE_DUMP_BUFFER_SIZE);
|
||||
char *buffer = taosMemoryMalloc(LOG_MAX_LINE_DUMP_BUFFER_SIZE);
|
||||
if (!buffer) return;
|
||||
int32_t len = taosBuildLogHead(buffer, flags);
|
||||
|
||||
va_list argpointer;
|
||||
|
|
Loading…
Reference in New Issue