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.500 2008/09/08 08:08:09 danielk1977 Exp $ +** $Id: main.c,v 1.501 2008/09/22 17:22:20 danielk1977 Exp $ */ #include "sqliteInt.h" #include #ifdef SQLITE_ENABLE_FTS3 @@ -133,10 +133,12 @@ sqlite3GlobalConfig.pInitMutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE); if( sqlite3GlobalConfig.bCoreMutex && !sqlite3GlobalConfig.pInitMutex ){ rc = SQLITE_NOMEM; } } + } + if( rc==SQLITE_OK ){ sqlite3GlobalConfig.nRefInitMutex++; } sqlite3_mutex_leave(pMaster); /* If unable to initialize the malloc subsystem, then return early. 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.65 2008/09/05 05:02:47 danielk1977 Exp $ +# $Id: malloc.test,v 1.66 2008/09/22 17:22:20 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -36,10 +36,11 @@ # puts stderr "This is a test. Ignore the error that follows:" sqlite3_memdebug_dump $testdir puts "Memory dump to file memdump.txt..." sqlite3_memdebug_dump memdump.txt + ifcapable bloblit&&subquery { do_malloc_test 1 -tclprep { db close } -tclbody { @@ -633,14 +634,27 @@ } -tclbody { db close sqlite3 db test.db db eval { INSERT INTO t1 VALUES(1, randomblob(210)) } } + +# Test that no memory is leaked following a malloc() failure in +# sqlite3_initialize(). +# +do_malloc_test 27 -tclprep { + db close + sqlite3_shutdown +} -tclbody { + set rc [sqlite3_initialize] + if {$rc == "SQLITE_NOMEM"} { + error "out of memory" + } +} # Ensure that no file descriptors were leaked. do_test malloc-99.X { catch {db close} set sqlite_open_file_count } {0} puts open-file-count=$sqlite_open_file_count finish_test