aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/util.c4
-rw-r--r--src/vacuum.c28
2 files changed, 10 insertions, 22 deletions
diff --git a/src/util.c b/src/util.c
index 1a8287b07..4064dadc9 100644
--- a/src/util.c
+++ b/src/util.c
@@ -14,7 +14,7 @@
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
-** $Id: util.c,v 1.166 2006/01/10 15:18:28 drh Exp $
+** $Id: util.c,v 1.167 2006/01/11 16:10:20 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -438,6 +438,7 @@ static void * OSMALLOC(int n){
ThreadData *pTsd = sqlite3ThreadData();
pTsd->nMaxAlloc = MAX(pTsd->nMaxAlloc, pTsd->nAlloc);
#endif
+ assert( sqlite3ThreadData()->mallocAllowed );
if( !failMalloc() ){
u32 *p;
p = (u32 *)sqlite3OsMalloc(n + TESTALLOC_OVERHEAD);
@@ -479,6 +480,7 @@ static void * OSREALLOC(void *pRealloc, int n){
ThreadData *pTsd = sqlite3ThreadData();
pTsd->nMaxAlloc = MAX(pTsd->nMaxAlloc, pTsd->nAlloc);
#endif
+ assert( sqlite3ThreadData()->mallocAllowed );
if( !failMalloc() ){
u32 *p = (u32 *)getOsPointer(pRealloc);
checkGuards(p);
diff --git a/src/vacuum.c b/src/vacuum.c
index 2d7f7652c..891bc9fcc 100644
--- a/src/vacuum.c
+++ b/src/vacuum.c
@@ -14,7 +14,7 @@
** Most of the code in this file may be omitted by defining the
** SQLITE_OMIT_VACUUM macro.
**
-** $Id: vacuum.c,v 1.55 2006/01/09 06:29:49 danielk1977 Exp $
+** $Id: vacuum.c,v 1.56 2006/01/11 16:10:20 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "vdbeInt.h"
@@ -103,7 +103,7 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
char *zSql = 0;
int rc2;
int saved_flags; /* Saved value of the db->flags */
- sqlite3_stmt *pDetach = 0;
+ Db *pDb = 0; /* Database to detach at end of vacuum */
/* Save the current value of the write-schema flag before setting it. */
saved_flags = db->flags;
@@ -150,15 +150,6 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
randomName((unsigned char*)&zTemp[nFilename+1]);
} while( sqlite3OsFileExists(zTemp) );
- /* Before we even attach it, compile a DETACH statement for vacuum_db. This
- ** way, if malloc() fails we can detach the database without needing to
- ** dynamically allocate memory.
- */
- rc = sqlite3_prepare(db, "DETACH vacuum_db", -1, &pDetach, 0);
- if( rc!=SQLITE_OK ){
- goto end_of_vacuum;
- }
-
/* Attach the temporary database as 'vacuum_db'. The synchronous pragma
** can be set to 'off' for this file, as it is not recovered if a crash
** occurs anyway. The integrity of the database is maintained by a
@@ -176,6 +167,7 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
sqliteFree(zSql);
zSql = 0;
if( rc!=SQLITE_OK ) goto end_of_vacuum;
+ pDb = &db->aDb[db->nDb-1];
assert( strcmp(db->aDb[db->nDb-1].zName,"vacuum_db")==0 );
pTemp = db->aDb[db->nDb-1].pBt;
sqlite3BtreeSetPageSize(pTemp, sqlite3BtreeGetPageSize(pMain),
@@ -310,18 +302,12 @@ end_of_vacuum:
*/
db->autoCommit = 1;
- if( pDetach ){
- int mf = sqlite3ThreadData()->mallocFailed;
- sqlite3ThreadData()->mallocFailed = 0;
+ if( pDb ){
sqlite3MallocDisallow();
- ((Vdbe *)pDetach)->expired = 0;
- sqlite3_step(pDetach);
- rc2 = sqlite3_finalize(pDetach);
- if( rc==SQLITE_OK ){
- rc = rc2;
- }
+ sqlite3BtreeClose(pDb->pBt);
sqlite3MallocAllow();
- sqlite3ThreadData()->mallocFailed = mf;
+ pDb->pBt = 0;
+ pDb->pSchema = 0;
}
/* If one of the execSql() calls above returned SQLITE_NOMEM, then the