提交 38948569 编写于 作者: H Hongze Cheng

fix: alter db pages memory leak

上级 d266d7a2
...@@ -349,6 +349,8 @@ static void tdbPCacheUnpinPage(SPCache *pCache, SPage *pPage) { ...@@ -349,6 +349,8 @@ static void tdbPCacheUnpinPage(SPCache *pCache, SPage *pPage) {
ASSERT(pPage->pLruNext == NULL); ASSERT(pPage->pLruNext == NULL);
tdbDebug("pCache:%p unpin page %p/%d/%d, nPages:%d", pCache, pPage, TDB_PAGE_PGNO(pPage), pPage->id, pCache->nPages);
if (pPage->id < pCache->nPages) {
pPage->pLruPrev = &(pCache->lru); pPage->pLruPrev = &(pCache->lru);
pPage->pLruNext = pCache->lru.pLruNext; pPage->pLruNext = pCache->lru.pLruNext;
pCache->lru.pLruNext->pLruPrev = pPage; pCache->lru.pLruNext->pLruPrev = pPage;
...@@ -358,6 +360,12 @@ static void tdbPCacheUnpinPage(SPCache *pCache, SPage *pPage) { ...@@ -358,6 +360,12 @@ static void tdbPCacheUnpinPage(SPCache *pCache, SPage *pPage) {
// printf("unpin page %d pgno %d pPage %p\n", pPage->id, TDB_PAGE_PGNO(pPage), pPage); // printf("unpin page %d pgno %d pPage %p\n", pPage->id, TDB_PAGE_PGNO(pPage), pPage);
tdbDebug("pcache/unpin page %p/%d/%d", pPage, TDB_PAGE_PGNO(pPage), pPage->id); tdbDebug("pcache/unpin page %p/%d/%d", pPage, TDB_PAGE_PGNO(pPage), pPage->id);
} else {
tdbDebug("pcache destroy page: %p/%d/%d", pPage, TDB_PAGE_PGNO(pPage), pPage->id);
tdbPCacheRemovePageFromHash(pCache, pPage);
tdbPageDestroy(pPage, tdbDefaultFree, NULL);
}
} }
static void tdbPCacheRemovePageFromHash(SPCache *pCache, SPage *pPage) { static void tdbPCacheRemovePageFromHash(SPCache *pCache, SPage *pPage) {
...@@ -443,10 +451,18 @@ static int tdbPCacheOpenImpl(SPCache *pCache) { ...@@ -443,10 +451,18 @@ static int tdbPCacheOpenImpl(SPCache *pCache) {
} }
static int tdbPCacheCloseImpl(SPCache *pCache) { static int tdbPCacheCloseImpl(SPCache *pCache) {
for (i32 iPage = 0; iPage < pCache->nPages; iPage++) { // free free page
if (pCache->aPage[iPage]) { for (SPage *pPage = pCache->pFree; pPage;) {
tdbPageDestroy(pCache->aPage[iPage], tdbDefaultFree, NULL); SPage *pPageT = pPage->pFreeNext;
pCache->aPage[iPage] = NULL; tdbPageDestroy(pPage, tdbDefaultFree, NULL);
pPage = pPageT;
}
for (int32_t iBucket = 0; iBucket < pCache->nHash; iBucket++) {
for (SPage *pPage = pCache->pgHash[iBucket]; pPage;) {
SPage *pPageT = pPage->pHashNext;
tdbPageDestroy(pPage, tdbDefaultFree, NULL);
pPage = pPageT;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册