diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 43822cd311f0d9c22f9cdf43c9da2d3dbc7b559a..cf7dd5010343fa86a3c322492771ce20083e226f 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -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; } diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index ceaac6dff139c9d0a8cf733fc03b5f784c4d31b3..383807cc35fd50179c6aff84451f01b7bdeedccf 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -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; } diff --git a/source/libs/tdb/src/db/tdbEnv.c b/source/libs/tdb/src/db/tdbEnv.c index d64b31234e170fc60c7b24d86905404c2c044fbd..c0c1343a4f337fa225c690abff9ba3a7bc218dec 100644 --- a/source/libs/tdb/src/db/tdbEnv.c +++ b/source/libs/tdb/src/db/tdbEnv.c @@ -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; } diff --git a/source/libs/tdb/src/db/tdbPCache.c b/source/libs/tdb/src/db/tdbPCache.c index 646b83298ead54fe1d262d93f867e5c21198f27c..aa056874267f7f09f4896d6429af00598e09a915 100644 --- a/source/libs/tdb/src/db/tdbPCache.c +++ b/source/libs/tdb/src/db/tdbPCache.c @@ -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; } diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index 194159260291e82b2b98c23d12547bbbedfbaabb..fbd5cb3aacf3be0151a15159400de4d44616f75a 100644 --- a/source/libs/tdb/src/db/tdbPager.c +++ b/source/libs/tdb/src/db/tdbPager.c @@ -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; }