提交 8fee813d 编写于 作者: M Minglei Jin

tdb/alloc-page: new param pTxn to fix memory leaking

上级 621d4b20
...@@ -338,10 +338,13 @@ int tdbPagerCommit(SPager *pPager, TXN *pTxn) { ...@@ -338,10 +338,13 @@ int tdbPagerCommit(SPager *pPager, TXN *pTxn) {
if (pTxn->jPageSet) { if (pTxn->jPageSet) {
hashset_remove(pTxn->jPageSet, (void *)((long)TDB_PAGE_PGNO(pPage))); hashset_remove(pTxn->jPageSet, (void *)((long)TDB_PAGE_PGNO(pPage)));
} }
tdbTrace("tdb/pager-commit: remove page: %p %d from dirty tree: %p", pPage, TDB_PAGE_PGNO(pPage), &pPager->rbt);
tdbPCacheRelease(pPager->pCache, pPage, pTxn); tdbPCacheRelease(pPager->pCache, pPage, pTxn);
} }
tdbTrace("pager/commit reset dirty tree: %p", &pPager->rbt); tdbTrace("tdb/pager-commit reset dirty tree: %p", &pPager->rbt);
tRBTreeCreate(&pPager->rbt, pageCmpFn); tRBTreeCreate(&pPager->rbt, pageCmpFn);
// sync the db file // sync the db file
...@@ -629,6 +632,8 @@ int tdbPagerFlushPage(SPager *pPager, TXN *pTxn) { ...@@ -629,6 +632,8 @@ int tdbPagerFlushPage(SPager *pPager, TXN *pTxn) {
return 0; return 0;
} }
static int tdbPagerAllocPage(SPager *pPager, SPgno *ppgno, TXN *pTxn);
int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage)(SPage *, void *, int), void *arg, int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage)(SPage *, void *, int), void *arg,
TXN *pTxn) { TXN *pTxn) {
SPage *pPage; SPage *pPage;
...@@ -643,7 +648,7 @@ int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPa ...@@ -643,7 +648,7 @@ int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPa
// alloc new page // alloc new page
if (pgno == 0) { if (pgno == 0) {
loadPage = 0; loadPage = 0;
ret = tdbPagerAllocPage(pPager, &pgno); ret = tdbPagerAllocPage(pPager, &pgno, pTxn);
if (ret < 0) { if (ret < 0) {
tdbError("tdb/pager: %p, ret: %d pgno: %" PRIu32 ", alloc page failed.", pPager, ret, pgno); tdbError("tdb/pager: %p, ret: %d pgno: %" PRIu32 ", alloc page failed.", pPager, ret, pgno);
return -1; return -1;
...@@ -706,7 +711,7 @@ int tdbPagerInsertFreePage(SPager *pPager, SPgno pgno, TXN *pTxn) { ...@@ -706,7 +711,7 @@ int tdbPagerInsertFreePage(SPager *pPager, SPgno pgno, TXN *pTxn) {
return code; return code;
} }
static int tdbPagerRemoveFreePage(SPager *pPager, SPgno *pPgno) { static int tdbPagerRemoveFreePage(SPager *pPager, SPgno *pPgno, TXN *pTxn) {
int code = 0; int code = 0;
TBC *pCur; TBC *pCur;
...@@ -714,13 +719,14 @@ static int tdbPagerRemoveFreePage(SPager *pPager, SPgno *pPgno) { ...@@ -714,13 +719,14 @@ static int tdbPagerRemoveFreePage(SPager *pPager, SPgno *pPgno) {
return 0; return 0;
} }
code = tdbTbcOpen(pPager->pEnv->pFreeDb, &pCur, NULL); code = tdbTbcOpen(pPager->pEnv->pFreeDb, &pCur, pTxn);
if (code < 0) { if (code < 0) {
return 0; return 0;
} }
code = tdbTbcMoveToFirst(pCur); code = tdbTbcMoveToFirst(pCur);
if (code) { if (code) {
tdbError("tdb/remove-free-page: moveto first failed with ret: %d.", code);
tdbTbcClose(pCur); tdbTbcClose(pCur);
return 0; return 0;
} }
...@@ -730,6 +736,7 @@ static int tdbPagerRemoveFreePage(SPager *pPager, SPgno *pPgno) { ...@@ -730,6 +736,7 @@ static int tdbPagerRemoveFreePage(SPager *pPager, SPgno *pPgno) {
code = tdbTbcGet(pCur, (const void **)&pKey, &nKey, NULL, NULL); code = tdbTbcGet(pCur, (const void **)&pKey, &nKey, NULL, NULL);
if (code < 0) { if (code < 0) {
tdbError("tdb/remove-free-page: tbc get failed with ret: %d.", code);
tdbTbcClose(pCur); tdbTbcClose(pCur);
return 0; return 0;
} }
...@@ -738,6 +745,7 @@ static int tdbPagerRemoveFreePage(SPager *pPager, SPgno *pPgno) { ...@@ -738,6 +745,7 @@ static int tdbPagerRemoveFreePage(SPager *pPager, SPgno *pPgno) {
code = tdbTbcDelete(pCur); code = tdbTbcDelete(pCur);
if (code < 0) { if (code < 0) {
tdbError("tdb/remove-free-page: tbc delete failed with ret: %d.", code);
tdbTbcClose(pCur); tdbTbcClose(pCur);
return 0; return 0;
} }
...@@ -745,9 +753,9 @@ static int tdbPagerRemoveFreePage(SPager *pPager, SPgno *pPgno) { ...@@ -745,9 +753,9 @@ static int tdbPagerRemoveFreePage(SPager *pPager, SPgno *pPgno) {
return 0; return 0;
} }
static int tdbPagerAllocFreePage(SPager *pPager, SPgno *ppgno) { static int tdbPagerAllocFreePage(SPager *pPager, SPgno *ppgno, TXN *pTxn) {
// TODO: Allocate a page from the free list // TODO: Allocate a page from the free list
return tdbPagerRemoveFreePage(pPager, ppgno); return tdbPagerRemoveFreePage(pPager, ppgno, pTxn);
} }
static int tdbPagerAllocNewPage(SPager *pPager, SPgno *ppgno) { static int tdbPagerAllocNewPage(SPager *pPager, SPgno *ppgno) {
...@@ -755,13 +763,13 @@ static int tdbPagerAllocNewPage(SPager *pPager, SPgno *ppgno) { ...@@ -755,13 +763,13 @@ static int tdbPagerAllocNewPage(SPager *pPager, SPgno *ppgno) {
return 0; return 0;
} }
int tdbPagerAllocPage(SPager *pPager, SPgno *ppgno) { static int tdbPagerAllocPage(SPager *pPager, SPgno *ppgno, TXN *pTxn) {
int ret; int ret;
*ppgno = 0; *ppgno = 0;
// Try to allocate from the free list of the pager // Try to allocate from the free list of the pager
ret = tdbPagerAllocFreePage(pPager, ppgno); ret = tdbPagerAllocFreePage(pPager, ppgno, pTxn);
if (ret < 0) { if (ret < 0) {
return -1; return -1;
} }
......
...@@ -199,9 +199,9 @@ int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initP ...@@ -199,9 +199,9 @@ int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initP
TXN *pTxn); TXN *pTxn);
void tdbPagerReturnPage(SPager *pPager, SPage *pPage, TXN *pTxn); void tdbPagerReturnPage(SPager *pPager, SPage *pPage, TXN *pTxn);
int tdbPagerInsertFreePage(SPager *pPager, SPgno pgno, TXN *pTxn); int tdbPagerInsertFreePage(SPager *pPager, SPgno pgno, TXN *pTxn);
int tdbPagerAllocPage(SPager *pPager, SPgno *ppgno); // int tdbPagerAllocPage(SPager *pPager, SPgno *ppgno);
int tdbPagerRestoreJournals(SPager *pPager); int tdbPagerRestoreJournals(SPager *pPager);
int tdbPagerRollback(SPager *pPager); int tdbPagerRollback(SPager *pPager);
// tdbPCache.c ==================================== // tdbPCache.c ====================================
#define TDB_PCACHE_PAGE \ #define TDB_PCACHE_PAGE \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册