Index: src/main.c ================================================================== --- src/main.c +++ src/main.c @@ -12,11 +12,11 @@ ** Main file for the SQLite library. The routines in this file ** implement the programmer interface to the library. Routines in ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: main.c,v 1.493 2008/08/21 20:21:35 drh Exp $ +** $Id: main.c,v 1.494 2008/08/27 19:01:58 danielk1977 Exp $ */ #include "sqliteInt.h" #include #ifdef SQLITE_ENABLE_FTS3 @@ -1479,11 +1479,10 @@ #endif db->pVfs = sqlite3_vfs_find(zVfs); if( !db->pVfs ){ rc = SQLITE_ERROR; - db->magic = SQLITE_MAGIC_SICK; sqlite3Error(db, rc, "no such vfs: %s", zVfs); goto opendb_out; } /* Add the default collation sequence BINARY. BINARY works for both UTF-8 @@ -1493,11 +1492,10 @@ createCollation(db, "BINARY", SQLITE_UTF8, 0, binCollFunc, 0); createCollation(db, "BINARY", SQLITE_UTF16BE, 0, binCollFunc, 0); createCollation(db, "BINARY", SQLITE_UTF16LE, 0, binCollFunc, 0); createCollation(db, "RTRIM", SQLITE_UTF8, (void*)1, binCollFunc, 0); if( db->mallocFailed ){ - db->magic = SQLITE_MAGIC_SICK; goto opendb_out; } db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 6, 0); assert( db->pDfltColl!=0 ); @@ -1516,11 +1514,10 @@ rc = sqlite3BtreeFactory(db, zFilename, 0, SQLITE_DEFAULT_CACHE_SIZE, flags | SQLITE_OPEN_MAIN_DB, &db->aDb[0].pBt); if( rc!=SQLITE_OK ){ sqlite3Error(db, rc, 0); - db->magic = SQLITE_MAGIC_SICK; goto opendb_out; } db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt); db->aDb[1].pSchema = sqlite3SchemaGet(db, 0); @@ -1606,13 +1603,16 @@ opendb_out: if( db ){ assert( db->mutex!=0 || isThreadsafe==0 || sqlite3Config.bFullMutex==0 ); sqlite3_mutex_leave(db->mutex); } - if( SQLITE_NOMEM==(rc = sqlite3_errcode(db)) ){ + rc = sqlite3_errcode(db); + if( rc==SQLITE_NOMEM ){ sqlite3_close(db); db = 0; + }else if( rc!=SQLITE_OK ){ + db->magic = SQLITE_MAGIC_SICK; } *ppDb = db; return sqlite3ApiExit(0, rc); } Index: test/malloc.test ================================================================== --- test/malloc.test +++ test/malloc.test @@ -14,11 +14,11 @@ # the SQLite library accepts a special command (sqlite3_memdebug_fail N C) # which causes the N-th malloc to fail. This special feature is used # to see what happens in the library if a malloc were to really fail # due to an out-of-memory situation. # -# $Id: malloc.test,v 1.63 2008/07/07 14:56:57 danielk1977 Exp $ +# $Id: malloc.test,v 1.64 2008/08/27 19:01:58 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -406,10 +406,13 @@ # Prepare statement set rc [catch {sqlite3_prepare $DB2 {SELECT * FROM sqlite_master} -1 X} msg] if {[sqlite3_errcode $DB2] eq "SQLITE_IOERR+12"} { error "out of memory" + } + if {[regexp ".*automatic extension loading.*" [sqlite3_errmsg $DB2]]} { + error "out of memory" } if {$rc} { error [string range $msg 4 end] } set STMT $msg