Fix two more memory leaks. (CVS 1603)
FossilOrigin-Name: 98b48704a1ce983677cdb269c24f7bca4ed606f7
This commit is contained in:
+28
-2
@@ -18,7 +18,7 @@
|
||||
** file simultaneously, or one process from reading the database while
|
||||
** another is writing.
|
||||
**
|
||||
** @(#) $Id: pager.c,v 1.128 2004/06/15 11:40:09 danielk1977 Exp $
|
||||
** @(#) $Id: pager.c,v 1.129 2004/06/16 07:45:24 danielk1977 Exp $
|
||||
*/
|
||||
#include "os.h" /* Must be first to enable large file support */
|
||||
#include "sqliteInt.h"
|
||||
@@ -459,6 +459,7 @@ static void pager_reset(Pager *pPager){
|
||||
*/
|
||||
static int pager_unwritelock(Pager *pPager){
|
||||
PgHdr *pPg;
|
||||
assert( !pPager->memDb );
|
||||
if( pPager->state<PAGER_RESERVED ){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -1354,6 +1355,14 @@ int sqlite3pager_close(Pager *pPager){
|
||||
}
|
||||
}
|
||||
for(pPg=pPager->pAll; pPg; pPg=pNext){
|
||||
#ifndef NDEBUG
|
||||
if( pPager->memDb ){
|
||||
PgHistory *pHist = PGHDR_TO_HIST(pPg, pPager);
|
||||
assert( !pPg->alwaysRollback );
|
||||
assert( !pHist->pOrig );
|
||||
assert( !pHist->pStmt );
|
||||
}
|
||||
#endif
|
||||
pNext = pPg->pNextAll;
|
||||
sqliteFree(pPg);
|
||||
}
|
||||
@@ -1939,6 +1948,7 @@ int sqlite3pager_unref(void *pData){
|
||||
*/
|
||||
static int pager_open_journal(Pager *pPager){
|
||||
int rc;
|
||||
assert( !pPager->memDb );
|
||||
assert( pPager->state>=PAGER_RESERVED );
|
||||
assert( pPager->journalOpen==0 );
|
||||
assert( pPager->useJournal );
|
||||
@@ -2278,6 +2288,8 @@ int sqlite3pager_overwrite(Pager *pPager, Pgno pgno, void *pData){
|
||||
void sqlite3pager_dont_write(Pager *pPager, Pgno pgno){
|
||||
PgHdr *pPg;
|
||||
|
||||
if( pPager->memDb ) return;
|
||||
|
||||
pPg = pager_lookup(pPager, pgno);
|
||||
pPg->alwaysRollback = 1;
|
||||
if( pPg && pPg->dirty ){
|
||||
@@ -2374,6 +2386,14 @@ int sqlite3pager_commit(Pager *pPager){
|
||||
pPg->pPrevStmt = pPg->pNextStmt = 0;
|
||||
pPg = pPg->pDirty;
|
||||
}
|
||||
#ifndef NDEBUG
|
||||
for(pPg=pPager->pAll; pPg; pPg=pPg->pNextAll){
|
||||
PgHistory *pHist = PGHDR_TO_HIST(pPg, pPager);
|
||||
assert( !pPg->alwaysRollback );
|
||||
assert( !pHist->pOrig );
|
||||
assert( !pHist->pStmt );
|
||||
}
|
||||
#endif
|
||||
pPager->pStmt = 0;
|
||||
pPager->state = PAGER_SHARED;
|
||||
return SQLITE_OK;
|
||||
@@ -2437,7 +2457,13 @@ int sqlite3pager_rollback(Pager *pPager){
|
||||
PgHdr *p;
|
||||
for(p=pPager->pAll; p; p=p->pNextAll){
|
||||
PgHistory *pHist;
|
||||
if( !p->alwaysRollback && !p->dirty ) continue;
|
||||
assert( !p->alwaysRollback );
|
||||
if( !p->dirty ){
|
||||
assert( !((PgHistory *)PGHDR_TO_HIST(p, pPager))->pOrig );
|
||||
assert( !((PgHistory *)PGHDR_TO_HIST(p, pPager))->pStmt );
|
||||
continue;
|
||||
}
|
||||
|
||||
pHist = PGHDR_TO_HIST(p, pPager);
|
||||
if( pHist->pOrig ){
|
||||
memcpy(PGHDR_TO_DATA(p), pHist->pOrig, pPager->pageSize);
|
||||
|
||||
+20
-1
@@ -14,12 +14,29 @@
|
||||
** This file contains functions for allocating memory, comparing
|
||||
** strings, and stuff like that.
|
||||
**
|
||||
** $Id: util.c,v 1.101 2004/06/12 00:42:35 danielk1977 Exp $
|
||||
** $Id: util.c,v 1.102 2004/06/16 07:45:29 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <stdarg.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#if SQLITE_DEBUG>2 && defined(__GLIBC__)
|
||||
#include <execinfo.h>
|
||||
void print_stack_trace(){
|
||||
void *bt[30];
|
||||
int i;
|
||||
int n = backtrace(bt, 30);
|
||||
|
||||
fprintf(stderr, "STACK: ");
|
||||
for(i=0; i<n;i++){
|
||||
fprintf(stderr, "%p ", bt[i]);
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
#else
|
||||
#define print_stack_trace()
|
||||
#endif
|
||||
|
||||
/*
|
||||
** If malloc() ever fails, this global variable gets set to 1.
|
||||
** This causes the library to abort and never again function.
|
||||
@@ -82,6 +99,7 @@ void *sqlite3Malloc_(int n, int bZero, char *zFile, int line){
|
||||
p = &pi[N_GUARD+1];
|
||||
memset(p, bZero==0, n);
|
||||
#if SQLITE_DEBUG>1
|
||||
print_stack_trace();
|
||||
fprintf(stderr,"%06d malloc %d bytes at 0x%x from %s:%d\n",
|
||||
++memcnt, n, (int)p, zFile,line);
|
||||
#endif
|
||||
@@ -189,6 +207,7 @@ void *sqlite3Realloc_(void *oldP, int n, char *zFile, int line){
|
||||
memset(oldPi, 0xab, (oldK+N_GUARD+2)*sizeof(int));
|
||||
free(oldPi);
|
||||
#if SQLITE_DEBUG>1
|
||||
print_stack_trace();
|
||||
fprintf(stderr,"%06d realloc %d to %d bytes at 0x%x to 0x%x at %s:%d\n",
|
||||
++memcnt, oldN, n, (int)oldP, (int)p, zFile, line);
|
||||
#endif
|
||||
|
||||
+2
-1
@@ -746,9 +746,10 @@ int sqlite3VdbeAggReset(sqlite *db, Agg *pAgg, KeyInfo *pKeyInfo){
|
||||
ctx.isError = 0;
|
||||
(*pAgg->apFunc[i]->xFinalize)(&ctx);
|
||||
pMem->z = ctx.pAgg;
|
||||
if( pMem->z!=0 && pMem->z!=pMem->z ){
|
||||
if( pMem->z!=0 && pMem->z!=pMem->zShort ){
|
||||
sqliteFree(pMem->z);
|
||||
}
|
||||
sqlite3VdbeMemRelease(&ctx.s);
|
||||
}else{
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user