Merge pull request #17398 from taosdata/fix/TD-19250-2
fix: coverity issues
This commit is contained in:
commit
50dfc57cda
|
@ -675,7 +675,7 @@ int32_t metaGetTbTSchemaEx(SMeta *pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sv
|
|||
SSchemaWrapper *pSchemaWrapper = &schema;
|
||||
|
||||
tDecoderInit(&dc, pData, nData);
|
||||
tDecodeSSchemaWrapper(&dc, pSchemaWrapper);
|
||||
(void)tDecodeSSchemaWrapper(&dc, pSchemaWrapper);
|
||||
tDecoderClear(&dc);
|
||||
tdbFree(pData);
|
||||
|
||||
|
|
|
@ -944,6 +944,7 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
|
|||
metaUpdateTagIdx(pMeta, &ctbEntry);
|
||||
}
|
||||
|
||||
ASSERT(ctbEntry.ctbEntry.pTags);
|
||||
SCtbIdxKey ctbIdxKey = {.suid = ctbEntry.ctbEntry.suid, .uid = uid};
|
||||
tdbTbUpsert(pMeta->pCtbIdx, &ctbIdxKey, sizeof(ctbIdxKey), ctbEntry.ctbEntry.pTags,
|
||||
((STag *)(ctbEntry.ctbEntry.pTags))->len, &pMeta->txn);
|
||||
|
@ -952,7 +953,7 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
|
|||
|
||||
tDecoderClear(&dc1);
|
||||
tDecoderClear(&dc2);
|
||||
if (ctbEntry.ctbEntry.pTags) taosMemoryFree((void *)ctbEntry.ctbEntry.pTags);
|
||||
taosMemoryFree((void *)ctbEntry.ctbEntry.pTags);
|
||||
if (ctbEntry.pBuf) taosMemoryFree(ctbEntry.pBuf);
|
||||
if (stbEntry.pBuf) tdbFree(stbEntry.pBuf);
|
||||
tdbTbcClose(pTbDbc);
|
||||
|
@ -1202,8 +1203,8 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) {
|
|||
SMetaEntry stbEntry = {0};
|
||||
STagIdxKey *pTagIdxKey = NULL;
|
||||
int32_t nTagIdxKey;
|
||||
const SSchema *pTagColumn; // = &stbEntry.stbEntry.schema.pSchema[0];
|
||||
const void *pTagData = NULL; //
|
||||
const SSchema *pTagColumn;
|
||||
const void *pTagData = NULL;
|
||||
int32_t nTagData = 0;
|
||||
SDecoder dc = {0};
|
||||
int32_t ret = 0;
|
||||
|
|
|
@ -1006,6 +1006,7 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const
|
|||
nLeft -= kLen;
|
||||
// pack partial val to local if any space left
|
||||
if (nLocal > nHeader + kLen + sizeof(SPgno)) {
|
||||
ASSERT(pVal != NULL && vLen != 0);
|
||||
memcpy(pCell + nHeader + kLen, pVal, nLocal - nHeader - kLen - sizeof(SPgno));
|
||||
nLeft -= nLocal - nHeader - kLen - sizeof(SPgno);
|
||||
}
|
||||
|
|
|
@ -105,6 +105,7 @@ static int tdbPCacheAlterImpl(SPCache *pCache, int32_t nPage) {
|
|||
for (int32_t iPage = pCache->nPages; iPage < nPage; iPage++) {
|
||||
if (tdbPageCreate(pCache->szPage, &aPage[iPage], tdbDefaultMalloc, NULL) < 0) {
|
||||
// TODO: handle error
|
||||
tdbOsFree(pCache->aPage);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -267,7 +268,7 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, TXN *pTxn)
|
|||
// 4. Try a create new page
|
||||
if (!pPage) {
|
||||
ret = tdbPageCreate(pCache->szPage, &pPage, pTxn->xMalloc, pTxn->xArg);
|
||||
if (ret < 0) {
|
||||
if (ret < 0 && pPage != NULL) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
return NULL;
|
||||
|
@ -300,8 +301,8 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, TXN *pTxn)
|
|||
pPage->pPager = pPageH->pPager;
|
||||
|
||||
memcpy(pPage->pData, pPageH->pData, pPage->pageSize);
|
||||
tdbDebug("pcache/pPageH: %p %d %p %p %d", pPageH, pPageH->pPageHdr - pPageH->pData, pPageH->xCellSize, pPage,
|
||||
TDB_PAGE_PGNO(pPageH));
|
||||
// tdbDebug("pcache/pPageH: %p %d %p %p %d", pPageH, pPageH->pPageHdr - pPageH->pData, pPageH->xCellSize, pPage,
|
||||
// TDB_PAGE_PGNO(pPageH));
|
||||
tdbPageInit(pPage, pPageH->pPageHdr - pPageH->pData, pPageH->xCellSize);
|
||||
pPage->kLen = pPageH->kLen;
|
||||
pPage->vLen = pPageH->vLen;
|
||||
|
|
|
@ -84,7 +84,8 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) {
|
|||
pPager->pCache = pCache;
|
||||
|
||||
pPager->fd = tdbOsOpen(pPager->dbFileName, TDB_O_CREAT | TDB_O_RDWR, 0755);
|
||||
if (pPager->fd < 0) {
|
||||
if (TDB_FD_INVALID(pPager->fd)) {
|
||||
// if (pPager->fd < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -226,7 +227,7 @@ int tdbPagerBegin(SPager *pPager, TXN *pTxn) {
|
|||
|
||||
// Open the journal
|
||||
pPager->jfd = tdbOsOpen(pPager->jFileName, TDB_O_CREAT | TDB_O_RDWR, 0755);
|
||||
if (pPager->jfd < 0) {
|
||||
if (TDB_FD_INVALID(pPager->jfd)) {
|
||||
tdbError("failed to open file due to %s. jFileName:%s", strerror(errno), pPager->jFileName);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
|
@ -365,7 +366,7 @@ int tdbPagerAbort(SPager *pPager, TXN *pTxn) {
|
|||
|
||||
// 4, remove the journal file
|
||||
tdbOsClose(pPager->jfd);
|
||||
tdbOsRemove(pPager->jFileName);
|
||||
(void)tdbOsRemove(pPager->jFileName);
|
||||
pPager->inTran = 0;
|
||||
|
||||
return 0;
|
||||
|
@ -540,7 +541,8 @@ static int tdbPagerWritePageToJournal(SPager *pPager, SPage *pPage) {
|
|||
|
||||
ret = tdbOsWrite(pPager->jfd, pPage->pData, pPage->pageSize);
|
||||
if (ret < 0) {
|
||||
tdbError("failed to write page data due to %s. file:%s, pageSize:%ld", strerror(errno), pPager->jFileName, pPage->pageSize);
|
||||
tdbError("failed to write page data due to %s. file:%s, pageSize:%ld", strerror(errno), pPager->jFileName,
|
||||
pPage->pageSize);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
|
@ -568,7 +570,8 @@ static int tdbPagerWritePageToDB(SPager *pPager, SPage *pPage) {
|
|||
|
||||
ret = tdbOsWrite(pPager->fd, pPage->pData, pPage->pageSize);
|
||||
if (ret < 0) {
|
||||
tdbError("failed to write page data due to %s. file:%s, pageSize:%ld", strerror(errno), pPager->dbFileName, pPage->pageSize);
|
||||
tdbError("failed to write page data due to %s. file:%s, pageSize:%ld", strerror(errno), pPager->dbFileName,
|
||||
pPage->pageSize);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
|
@ -603,11 +606,13 @@ int tdbPagerRestore(SPager *pPager, SBTree *pBt) {
|
|||
|
||||
int ret = tdbOsRead(jfd, &pgno, sizeof(pgno));
|
||||
if (ret < 0) {
|
||||
tdbOsFree(pageBuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = tdbOsRead(jfd, pageBuf, pPager->pageSize);
|
||||
if (ret < 0) {
|
||||
tdbOsFree(pageBuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -615,13 +620,16 @@ int tdbPagerRestore(SPager *pPager, SBTree *pBt) {
|
|||
if (tdbOsLSeek(pPager->fd, offset, SEEK_SET) < 0) {
|
||||
tdbError("failed to lseek fd due to %s. file:%s, offset:%ld", strerror(errno), pPager->dbFileName, offset);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
tdbOsFree(pageBuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = tdbOsWrite(pPager->fd, pageBuf, pPager->pageSize);
|
||||
if (ret < 0) {
|
||||
tdbError("failed to write buf due to %s. file: %s, bufsize:%d", strerror(errno), pPager->dbFileName, pPager->pageSize);
|
||||
tdbError("failed to write buf due to %s. file: %s, bufsize:%d", strerror(errno), pPager->dbFileName,
|
||||
pPager->pageSize);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
tdbOsFree(pageBuf);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -629,6 +637,7 @@ int tdbPagerRestore(SPager *pPager, SBTree *pBt) {
|
|||
if (tdbOsFSync(pPager->fd) < 0) {
|
||||
tdbError("failed to fsync fd due to %s. dbfile:%s", strerror(errno), pPager->dbFileName);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
tdbOsFree(pageBuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -106,11 +106,13 @@ int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprF
|
|||
// pTb->pBt
|
||||
ret = tdbBtreeOpen(keyLen, valLen, pPager, tbname, pgno, keyCmprFn, &(pTb->pBt));
|
||||
if (ret < 0) {
|
||||
tdbOsFree(pTb);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = tdbPagerRestore(pPager, pTb->pBt);
|
||||
if (ret < 0) {
|
||||
tdbOsFree(pTb);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,8 @@ extern "C" {
|
|||
/* file */
|
||||
typedef TdFilePtr tdb_fd_t;
|
||||
|
||||
#define TDB_FD_INVALID(fd) (fd == NULL)
|
||||
|
||||
#define TDB_O_CREAT TD_FILE_CREATE
|
||||
#define TDB_O_WRITE TD_FILE_WRITE
|
||||
#define TDB_O_READ TD_FILE_READ
|
||||
|
@ -141,4 +143,4 @@ typedef pthread_mutex_t tdb_mutex_t;
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TDB_OS_H_*/
|
||||
#endif /*_TDB_OS_H_*/
|
||||
|
|
Loading…
Reference in New Issue