提交 6a0e89c4 编写于 作者: H Hongze Cheng

fix: memory leak

上级 4059d93c
......@@ -113,7 +113,9 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, tdb_cmpr_fn_t kcmpr, SB
}
int tdbBtreeClose(SBTree *pBt) {
// TODO
if (pBt) {
tdbOsFree(pBt);
}
return 0;
}
......
......@@ -66,7 +66,10 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprFn
}
int tdbDbClose(TDB *pDb) {
// TODO
if (pDb) {
tdbBtreeClose(pDb->pBt);
tdbOsFree(pDb);
}
return 0;
}
......
......@@ -56,7 +56,7 @@ int tdbEnvOpen(const char *rootDir, int szPage, int pages, TENV **ppEnv) {
pEnv->nPgrHash = 8;
tsize = sizeof(SPager *) * pEnv->nPgrHash;
pEnv->pgrHash = tdbRealloc(pEnv->pgrHash, tsize);
pEnv->pgrHash = tdbOsMalloc(tsize);
if (pEnv->pgrHash == NULL) {
return -1;
}
......@@ -69,7 +69,19 @@ int tdbEnvOpen(const char *rootDir, int szPage, int pages, TENV **ppEnv) {
}
int tdbEnvClose(TENV *pEnv) {
// TODO
SPager *pPager;
if (pEnv) {
for (pPager = pEnv->pgrList; pPager; pPager = pEnv->pgrList) {
pEnv->pgrList = pPager->pNext;
tdbPagerClose(pPager);
}
tdbPCacheClose(pEnv->pCache);
tdbOsFree(pEnv->pgrHash);
tdbOsFree(pEnv);
}
return 0;
}
......
......@@ -292,6 +292,10 @@ static int tdbPCacheOpenImpl(SPCache *pCache) {
pPage->pFreeNext = pCache->pFree;
pCache->pFree = pPage;
pCache->nFree++;
// add to local list
pPage->pCacheNext = pCache->pList;
pCache->pList = pPage;
}
// Open the hash table
......@@ -317,9 +321,10 @@ static int tdbPCacheCloseImpl(SPCache *pCache) {
for (pPage = pCache->pList; pPage; pPage = pCache->pList) {
pCache->pList = pPage->pCacheNext;
tdbPageDestroy(pPage, NULL, NULL);
tdbPageDestroy(pPage, tdbDefaultFree, NULL);
}
tdbOsFree(pCache->pgHash);
tdbPCacheDestroyLock(pCache);
return 0;
}
......@@ -88,7 +88,13 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) {
}
int tdbPagerClose(SPager *pPager) {
// TODO
if (pPager) {
if (pPager->inTran) {
tdbOsClose(pPager->jfd);
}
tdbOsClose(pPager->fd);
tdbOsFree(pPager);
}
return 0;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册