Merge pull request #27980 from taosdata/enh/addMemReturnOfIndex
check return of memalloc
This commit is contained in:
commit
8037f835b9
|
@ -164,6 +164,9 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
|||
if (argc < 2) return 0;
|
||||
|
||||
global.envCmd = taosMemoryMalloc((argc - 1) * sizeof(char *));
|
||||
if (global.envCmd == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
memset(global.envCmd, 0, (argc - 1) * sizeof(char *));
|
||||
for (int32_t i = 1; i < argc; ++i) {
|
||||
if (strcmp(argv[i], "-c") == 0) {
|
||||
|
|
|
@ -150,6 +150,10 @@ int32_t dmReadEps(SDnodeData *pData) {
|
|||
}
|
||||
|
||||
char *tmp = taosMemoryMalloc(scopeLen + 1);
|
||||
if (tmp == NULL) {
|
||||
dError("failed to malloc memory for tsEncryptScope:%s", tsEncryptScope);
|
||||
goto _OVER;
|
||||
}
|
||||
memset(tmp, 0, scopeLen + 1);
|
||||
memcpy(tmp, tsEncryptScope, scopeLen);
|
||||
|
||||
|
|
|
@ -342,6 +342,11 @@ static int32_t dmCompareEncryptKey(char *file, char *key, bool toLogFile) {
|
|||
|
||||
int len = ENCRYPTED_LEN(size);
|
||||
result = taosMemoryMalloc(len);
|
||||
if (result == NULL) {
|
||||
code = terrno;
|
||||
encryptError("failed to alloc memory file:%s since %s", file, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
SCryptOpts opts = {0};
|
||||
strncpy(opts.key, key, ENCRYPT_KEY_LEN);
|
||||
|
|
|
@ -80,6 +80,10 @@ static int32_t cacheSearchTerm(void* cache, SIndexTerm* term, SIdxTRslt* tr, STe
|
|||
IndexCache* pCache = mem->pCache;
|
||||
|
||||
CacheTerm* pCt = taosMemoryCalloc(1, sizeof(CacheTerm));
|
||||
if (pCt == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
pCt->colVal = term->colVal;
|
||||
pCt->version = atomic_load_64(&pCache->version);
|
||||
|
||||
|
@ -290,6 +294,10 @@ static int32_t cacheSearchCompareFunc_JSON(void* cache, SIndexTerm* term, SIdxTR
|
|||
IndexCache* pCache = mem->pCache;
|
||||
|
||||
CacheTerm* pCt = taosMemoryCalloc(1, sizeof(CacheTerm));
|
||||
if (pCt == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
pCt->colVal = term->colVal;
|
||||
pCt->version = atomic_load_64(&pCache->version);
|
||||
|
||||
|
@ -539,6 +547,10 @@ int idxCacheSchedToMerge(IndexCache* pCache, bool notify) {
|
|||
schedMsg.ahandle = pCache;
|
||||
if (notify) {
|
||||
schedMsg.thandle = taosMemoryMalloc(1);
|
||||
if (schedMsg.thandle == NULL) {
|
||||
indexError("fail to schedule merge task");
|
||||
return terrno;
|
||||
}
|
||||
}
|
||||
schedMsg.msg = NULL;
|
||||
idxAcquireRef(pCache->index->refId);
|
||||
|
|
|
@ -260,7 +260,10 @@ char* idxPackJsonData(SIndexTerm* itm) {
|
|||
|
||||
int32_t sz = itm->nColName + itm->nColVal + sizeof(uint8_t) + sizeof(JSON_VALUE_DELIM) * 2 + 1;
|
||||
char* buf = (char*)taosMemoryCalloc(1, sz);
|
||||
char* p = buf;
|
||||
if (buf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
char* p = buf;
|
||||
|
||||
memcpy(p, itm->colName, itm->nColName);
|
||||
p += itm->nColName;
|
||||
|
@ -288,7 +291,10 @@ char* idxPackJsonDataPrefix(SIndexTerm* itm, int32_t* skip) {
|
|||
|
||||
int32_t sz = itm->nColName + itm->nColVal + sizeof(uint8_t) + sizeof(JSON_VALUE_DELIM) * 2 + 1;
|
||||
char* buf = (char*)taosMemoryCalloc(1, sz);
|
||||
char* p = buf;
|
||||
if (buf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
char* p = buf;
|
||||
|
||||
memcpy(p, itm->colName, itm->nColName);
|
||||
p += itm->nColName;
|
||||
|
@ -315,7 +321,11 @@ char* idxPackJsonDataPrefixNoType(SIndexTerm* itm, int32_t* skip) {
|
|||
|
||||
int32_t sz = itm->nColName + itm->nColVal + sizeof(uint8_t) + sizeof(JSON_VALUE_DELIM) * 2 + 1;
|
||||
char* buf = (char*)taosMemoryCalloc(1, sz);
|
||||
char* p = buf;
|
||||
if (buf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char* p = buf;
|
||||
|
||||
memcpy(p, itm->colName, itm->nColName);
|
||||
p += itm->nColName;
|
||||
|
|
|
@ -57,9 +57,17 @@ void fstUnFinishedNodesDestroy(FstUnFinishedNodes* nodes) {
|
|||
|
||||
void fstUnFinishedNodesPushEmpty(FstUnFinishedNodes* nodes, bool isFinal) {
|
||||
FstBuilderNode* node = taosMemoryMalloc(sizeof(FstBuilderNode));
|
||||
if (node == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
node->isFinal = isFinal;
|
||||
node->finalOutput = 0;
|
||||
node->trans = taosArrayInit(16, sizeof(FstTransition));
|
||||
if (node->trans == NULL) {
|
||||
taosMemoryFree(node);
|
||||
return;
|
||||
}
|
||||
|
||||
FstBuilderNodeUnfinished un = {.node = node, .last = NULL};
|
||||
if (taosArrayPush(nodes->stack, &un) == NULL) {
|
||||
|
@ -112,6 +120,9 @@ void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes* nodes, FstSlice bs, Output
|
|||
|
||||
for (uint64_t i = 1; i < len; i++) {
|
||||
FstBuilderNode* n = taosMemoryMalloc(sizeof(FstBuilderNode));
|
||||
if (n == NULL) {
|
||||
return;
|
||||
}
|
||||
n->isFinal = false;
|
||||
n->finalOutput = 0;
|
||||
n->trans = taosArrayInit(16, sizeof(FstTransition));
|
||||
|
@ -295,6 +306,9 @@ void fstStateCompileForAnyTrans(IdxFstFile* w, CompiledAddr addr, FstBuilderNode
|
|||
if (sz > TRANS_INDEX_THRESHOLD) {
|
||||
// A value of 255 indicates that no transition exists for the byte at that idx
|
||||
uint8_t* index = (uint8_t*)taosMemoryMalloc(sizeof(uint8_t) * 256);
|
||||
if (index == NULL) {
|
||||
return;
|
||||
}
|
||||
memset(index, 255, sizeof(uint8_t) * 256);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
FstTransition* t = taosArrayGet(node->trans, i);
|
||||
|
@ -973,6 +987,10 @@ Fst* fstCreate(FstSlice* slice) {
|
|||
fst->meta->checkSum = checkSum;
|
||||
|
||||
FstSlice* s = taosMemoryCalloc(1, sizeof(FstSlice));
|
||||
if (s == NULL) {
|
||||
goto FST_CREAT_FAILED;
|
||||
}
|
||||
|
||||
*s = fstSliceCopy(slice, 0, FST_SLICE_LEN(slice) - 1);
|
||||
fst->data = s;
|
||||
|
||||
|
@ -1326,6 +1344,9 @@ FStmStRslt* stmStNextWith(FStmSt* sws, streamCallback__fn callback) {
|
|||
|
||||
int32_t isz = taosArrayGetSize(sws->inp);
|
||||
uint8_t* buf = (uint8_t*)taosMemoryMalloc(isz * sizeof(uint8_t));
|
||||
if (buf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
for (uint32_t i = 0; i < isz; i++) {
|
||||
buf[i] = *(uint8_t*)taosArrayGet(sws->inp, i);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,11 @@ StartWithStateValue* startWithStateValueCreate(StartWithStateKind kind, ValueTyp
|
|||
} else if (ty == FST_CHAR) {
|
||||
size_t len = strlen((char*)val);
|
||||
sv->ptr = (char*)taosMemoryCalloc(1, len + 1);
|
||||
if (sv->ptr == NULL) {
|
||||
taosMemoryFree(sv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(sv->ptr, val, len);
|
||||
} else if (ty == FST_ARRAY) {
|
||||
// TODO,
|
||||
|
@ -63,6 +68,11 @@ StartWithStateValue* startWithStateValueDump(StartWithStateValue* sv) {
|
|||
} else if (nsv->type == FST_CHAR) {
|
||||
size_t len = strlen(sv->ptr);
|
||||
nsv->ptr = (char*)taosMemoryCalloc(1, len + 1);
|
||||
if (nsv->ptr == NULL) {
|
||||
taosMemoryFree(nsv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(nsv->ptr, sv->ptr, len);
|
||||
} else if (nsv->type == FST_ARRAY) {
|
||||
//
|
||||
|
|
|
@ -134,6 +134,9 @@ static int idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t of
|
|||
int32_t cacheMemSize = sizeof(SDataBlock) + kBlockSize;
|
||||
|
||||
SDataBlock* blk = taosMemoryCalloc(1, cacheMemSize);
|
||||
if (blk == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
blk->blockId = blkId;
|
||||
blk->nread = taosPReadFile(ctx->file.pFile, blk->buf, kBlockSize, blkId * kBlockSize);
|
||||
if (blk->nread < kBlockSize && blk->nread < len) {
|
||||
|
@ -211,6 +214,10 @@ IFileCtx* idxFileCtxCreate(WriterType type, const char* path, bool readOnly, int
|
|||
ctx->file.wBufOffset = 0;
|
||||
ctx->file.wBufCap = kBlockSize * 4;
|
||||
ctx->file.wBuf = taosMemoryCalloc(1, ctx->file.wBufCap);
|
||||
if (ctx->file.wBuf == NULL) {
|
||||
indexError("failed to allocate memory for write buffer");
|
||||
goto END;
|
||||
}
|
||||
} else {
|
||||
ctx->file.pFile = taosOpenFile(path, TD_FILE_READ);
|
||||
code = taosFStatFile(ctx->file.pFile, &ctx->file.size, NULL);
|
||||
|
@ -228,6 +235,11 @@ IFileCtx* idxFileCtxCreate(WriterType type, const char* path, bool readOnly, int
|
|||
}
|
||||
} else if (ctx->type == TMEMORY) {
|
||||
ctx->mem.buf = taosMemoryCalloc(1, sizeof(char) * capacity);
|
||||
if (ctx->mem.buf == NULL) {
|
||||
indexError("failed to allocate memory for memory buffer");
|
||||
goto END;
|
||||
}
|
||||
|
||||
ctx->mem.cap = capacity;
|
||||
}
|
||||
|
||||
|
@ -325,6 +337,10 @@ int idxFileFlush(IdxFstFile* write) {
|
|||
|
||||
void idxFilePackUintIn(IdxFstFile* writer, uint64_t n, uint8_t nBytes) {
|
||||
uint8_t* buf = taosMemoryCalloc(8, sizeof(uint8_t));
|
||||
if (buf == NULL) {
|
||||
indexError("failed to allocate memory for packing uint");
|
||||
return;
|
||||
}
|
||||
for (uint8_t i = 0; i < nBytes; i++) {
|
||||
buf[i] = (uint8_t)n;
|
||||
n = n >> 8;
|
||||
|
|
|
@ -80,6 +80,10 @@ FstSlice fstSliceCreate(uint8_t* data, uint64_t len) {
|
|||
str->ref = 1;
|
||||
str->len = len;
|
||||
str->data = taosMemoryMalloc(len * sizeof(uint8_t));
|
||||
if (str == NULL || str->data == NULL) {
|
||||
taosMemoryFree(str);
|
||||
return (FstSlice){.str = NULL, .start = 0, .end = 0};
|
||||
}
|
||||
|
||||
if (data != NULL && str->data != NULL) {
|
||||
memcpy(str->data, data, len);
|
||||
|
|
|
@ -799,6 +799,10 @@ static bool tfileIteratorNext(Iterate* iiter) {
|
|||
int32_t sz = 0;
|
||||
char* ch = (char*)fstSliceData(&rt->data, &sz);
|
||||
colVal = taosMemoryCalloc(1, sz + 1);
|
||||
if (colVal == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(colVal, ch, sz);
|
||||
|
||||
offset = (uint64_t)(rt->out.out);
|
||||
|
@ -835,6 +839,10 @@ Iterate* tfileIteratorCreate(TFileReader* reader) {
|
|||
}
|
||||
|
||||
Iterate* iter = taosMemoryCalloc(1, sizeof(Iterate));
|
||||
if (iter == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
iter->iter = tfileFstIteratorCreate(reader);
|
||||
if (iter->iter == NULL) {
|
||||
taosMemoryFree(iter);
|
||||
|
@ -843,6 +851,11 @@ Iterate* tfileIteratorCreate(TFileReader* reader) {
|
|||
iter->next = tfileIteratorNext;
|
||||
iter->getValue = tifileIterateGetValue;
|
||||
iter->val.val = taosArrayInit(1, sizeof(uint64_t));
|
||||
if (iter->val.val == NULL) {
|
||||
tfileIteratorDestroy(iter);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
iter->val.colVal = NULL;
|
||||
return iter;
|
||||
}
|
||||
|
|
|
@ -90,6 +90,10 @@ int32_t iUnion(SArray *in, SArray *out) {
|
|||
}
|
||||
|
||||
MergeIndex *mi = taosMemoryCalloc(sz, sizeof(MergeIndex));
|
||||
if (mi == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
for (int i = 0; i < sz; i++) {
|
||||
SArray *t = taosArrayGetP(in, i);
|
||||
mi[i].len = (int32_t)taosArrayGetSize(t);
|
||||
|
|
Loading…
Reference in New Issue