mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-16 23:02:26 +03:00
The sqlite3WhereMalloc() routine allocates memory that is automatically
deleted when the corresponding WhereInfo object is destroyed. FossilOrigin-Name: f237e1d8cc41b937f34288daebfacf5f7b0990a807a805e0cb6b45bc730192d6
This commit is contained in:
37
src/where.c
37
src/where.c
@@ -253,6 +253,30 @@ Bitmask sqlite3WhereGetMask(WhereMaskSet *pMaskSet, int iCursor){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Allocate memory that is automatically freed when pWInfo is freed.
|
||||
*/
|
||||
void *sqlite3WhereMalloc(WhereInfo *pWInfo, u64 nByte){
|
||||
WhereMemBlock *pBlock;
|
||||
pBlock = sqlite3DbMallocRawNN(pWInfo->pParse->db, nByte+sizeof(*pBlock));
|
||||
if( pBlock ){
|
||||
pBlock->pNext = pWInfo->pMemToFree;
|
||||
pBlock->sz = nByte;
|
||||
pWInfo->pMemToFree = pBlock;
|
||||
pBlock++;
|
||||
}
|
||||
return (void*)pBlock;
|
||||
}
|
||||
void *sqlite3WhereRealloc(WhereInfo *pWInfo, void *pOld, u64 nByte){
|
||||
void *pNew = sqlite3WhereMalloc(pWInfo, nByte);
|
||||
if( pNew && pOld ){
|
||||
WhereMemBlock *pOldBlk = (WhereMemBlock*)pOld;
|
||||
pOldBlk--;
|
||||
assert( pOldBlk->sz<nByte );
|
||||
memcpy(pNew, pOld, pOldBlk->sz);
|
||||
}
|
||||
return pNew;
|
||||
}
|
||||
|
||||
/*
|
||||
** Create a new mask for cursor iCursor.
|
||||
**
|
||||
@@ -2216,15 +2240,7 @@ static void whereLoopDelete(sqlite3 *db, WhereLoop *p){
|
||||
** Free a WhereInfo structure
|
||||
*/
|
||||
static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
|
||||
int i;
|
||||
assert( pWInfo!=0 );
|
||||
for(i=0; i<pWInfo->nLevel; i++){
|
||||
WhereLevel *pLevel = &pWInfo->a[i];
|
||||
if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE)!=0 ){
|
||||
assert( (pLevel->pWLoop->wsFlags & WHERE_MULTI_OR)==0 );
|
||||
sqlite3DbFree(db, pLevel->u.in.aInLoop);
|
||||
}
|
||||
}
|
||||
sqlite3WhereClauseClear(&pWInfo->sWC);
|
||||
while( pWInfo->pLoops ){
|
||||
WhereLoop *p = pWInfo->pLoops;
|
||||
@@ -2232,6 +2248,11 @@ static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
|
||||
whereLoopDelete(db, p);
|
||||
}
|
||||
assert( pWInfo->pExprMods==0 );
|
||||
while( pWInfo->pMemToFree ){
|
||||
WhereMemBlock *pNext = pWInfo->pMemToFree->pNext;
|
||||
sqlite3DbFreeNN(db, pWInfo->pMemToFree);
|
||||
pWInfo->pMemToFree = pNext;
|
||||
}
|
||||
sqlite3DbFreeNN(db, pWInfo);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user