Index: src/hash.c ================================================================== --- src/hash.c +++ src/hash.c @@ -10,11 +10,11 @@ ** ************************************************************************* ** This is the implementation of generic hash-tables ** used in SQLite. ** -** $Id: hash.c,v 1.16 2005/01/31 12:56:44 danielk1977 Exp $ +** $Id: hash.c,v 1.17 2005/10/03 15:11:09 drh Exp $ */ #include "sqliteInt.h" #include /* Turn bulk memory into a hash table object by initializing the @@ -292,10 +292,15 @@ if( pH->copyKey && elem->pKey ){ sqliteFree(elem->pKey); } sqliteFree( elem ); pH->count--; + if( pH->count<=0 ){ + assert( pH->first==0 ); + assert( pH->count==0 ); + sqlite3HashClear(pH); + } } /* Attempt to locate an element of the hash table pH with a key ** that matches pKey,nKey. Return the data for this element if it is ** found, or NULL if there is no match. ADDED test/manydb.test Index: test/manydb.test ================================================================== --- /dev/null +++ test/manydb.test @@ -0,0 +1,74 @@ +# 2005 October 3 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests the ability of the library to open +# many different databases at the same time without leaking memory. +# +# $Id: manydb.test,v 1.1 2005/10/03 15:11:09 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set N 300 + +# Create a bunch of random database names +# +unset -nocomplain dbname +unset -nocomplain used +for {set i 0} {$i<$N} {incr i} { + while 1 { + set name test-[format %08x [expr {int(rand()*0x7fffffff)}]].db + if {[info exists used($name)]} continue + set dbname($i) $name + set used($name) $i + break + } +} + +# Create a bunch of databases +# +for {set i 0} {$i<$N} {incr i} { + do_test manydb-1.$i { + sqlite3 db$i $dbname($i) + execsql { + CREATE TABLE t1(a,b); + BEGIN; + INSERT INTO t1 VALUES(1,2); + } db$i + } {} +} + +# Finish the transactions +# +for {set i 0} {$i<$N} {incr i} { + do_test manydb-2.$i { + execsql { + COMMIT; + SELECT * FROM t1; + } db$i + } {1 2} +} + + +# Close the databases and erase the files. +# +for {set i 0} {$i<$N} {incr i} { + do_test manydb-3.$i { + db$i close + file delete -force $dbname($i) + } {} +} + + + + +finish_test