1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Add some test logic to the new memory allocation subsystem. (Lots more needed.)

The test suite is currently indicating memory leaks, though it is unclear if
this is a true code problem or just an instrumentation problem. (CVS 5240)

FossilOrigin-Name: cb1f11cd9764cf0275e88e1f6342e366e5536bfd
This commit is contained in:
drh
2008-06-19 00:16:08 +00:00
parent 6a9773e884
commit f714199054
13 changed files with 620 additions and 127 deletions

View File

@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
** $Id: btree.c,v 1.466 2008/06/18 17:09:10 danielk1977 Exp $
** $Id: btree.c,v 1.467 2008/06/19 00:16:08 drh Exp $
**
** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information.
@@ -1400,6 +1400,24 @@ static int removeFromSharingList(BtShared *pBt){
#endif
}
/*
** Make sure pBt->pTmpSpace points to an allocation of
** MX_CELL_SIZE(pBt) bytes.
*/
static void allocateTempSpace(BtShared *pBt){
if( !pBt->pTmpSpace ){
pBt->pTmpSpace = sqlite3PageMalloc( pBt->pageSize );
}
}
/*
** Free the pBt->pTmpSpace allocation
*/
static void freeTempSpace(BtShared *pBt){
sqlite3PageFree( pBt->pTmpSpace);
pBt->pTmpSpace = 0;
}
/*
** Close an open database and invalidate all cursors.
*/
@@ -1444,8 +1462,7 @@ int sqlite3BtreeClose(Btree *p){
pBt->xFreeSchema(pBt->pSchema);
}
sqlite3_free(pBt->pSchema);
sqlite3_free(pBt->pTmpSpace);
sqlite3_free(pBt);
freeTempSpace(pBt);
}
#ifndef SQLITE_OMIT_SHARED_CACHE
@@ -1549,8 +1566,7 @@ int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve){
assert( (pageSize & 7)==0 );
assert( !pBt->pPage1 && !pBt->pCursor );
pBt->pageSize = pageSize;
sqlite3_free(pBt->pTmpSpace);
pBt->pTmpSpace = 0;
freeTempSpace(pBt);
rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize);
}
pBt->usableSize = pBt->pageSize - nReserve;
@@ -1698,8 +1714,7 @@ static int lockBtree(BtShared *pBt){
releasePage(pPage1);
pBt->usableSize = usableSize;
pBt->pageSize = pageSize;
sqlite3_free(pBt->pTmpSpace);
pBt->pTmpSpace = 0;
freeTempSpace(pBt);
sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize);
return SQLITE_OK;
}
@@ -5677,16 +5692,6 @@ static int checkReadLocks(
return SQLITE_OK;
}
/*
** Make sure pBt->pTmpSpace points to an allocation of
** MX_CELL_SIZE(pBt) bytes.
*/
static void allocateTempSpace(BtShared *pBt){
if( !pBt->pTmpSpace ){
pBt->pTmpSpace = sqlite3Malloc(MX_CELL_SIZE(pBt));
}
}
/*
** Insert a new record into the BTree. The key is given by (pKey,nKey)
** and the data is given by (pData,nData). The cursor is used only to
@@ -6643,8 +6648,9 @@ static int checkTreePage(
*/
data = pPage->aData;
hdr = pPage->hdrOffset;
hit = sqlite3MallocZero( usableSize );
hit = sqlite3PageMalloc( pBt->pageSize );
if( hit ){
memset(hit, 0, usableSize );
memset(hit, 1, get2byte(&data[hdr+5]));
nCell = get2byte(&data[hdr+3]);
cellStart = hdr + 12 - 4*pPage->leaf;
@@ -6686,7 +6692,7 @@ static int checkTreePage(
cnt, data[hdr+7], iPage);
}
}
sqlite3_free(hit);
sqlite3PageFree(hit);
releasePage(pPage);
return depth+1;