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

fix: alter db pages memory leak

上级 d266d7a2
...@@ -349,15 +349,23 @@ static void tdbPCacheUnpinPage(SPCache *pCache, SPage *pPage) { ...@@ -349,15 +349,23 @@ static void tdbPCacheUnpinPage(SPCache *pCache, SPage *pPage) {
ASSERT(pPage->pLruNext == NULL); ASSERT(pPage->pLruNext == NULL);
pPage->pLruPrev = &(pCache->lru); tdbDebug("pCache:%p unpin page %p/%d/%d, nPages:%d", pCache, pPage, TDB_PAGE_PGNO(pPage), pPage->id, pCache->nPages);
pPage->pLruNext = pCache->lru.pLruNext; if (pPage->id < pCache->nPages) {
pCache->lru.pLruNext->pLruPrev = pPage; pPage->pLruPrev = &(pCache->lru);
pCache->lru.pLruNext = pPage; pPage->pLruNext = pCache->lru.pLruNext;
pCache->lru.pLruNext->pLruPrev = pPage;
pCache->lru.pLruNext = pPage;
pCache->nRecyclable++; pCache->nRecyclable++;
// 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.
先完成此消息的编辑!
想要评论请 注册