]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
The hash tables deallocate when empty in order to avoid nuisanse complaints
authordrh <drh@noemail.net>
Mon, 3 Oct 2005 15:11:08 +0000 (15:11 +0000)
committerdrh <drh@noemail.net>
Mon, 3 Oct 2005 15:11:08 +0000 (15:11 +0000)
from valgrind.  Added tests to verify no hash table memory leaks in os_unix.c. (CVS 2738)

FossilOrigin-Name: 080eadca582a49a069a76ed113ec15e9bce2955a

manifest
manifest.uuid
src/hash.c
test/manydb.test [new file with mode: 0644]

index b90f90873f38c46a78a11c338bf65a051e543153..a12fcf347d5219c61dc3cf6ecd5e9baec144be0b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Make\ssure\sthe\sdefault\sstorage\sfor\svirtual\stables\sis\sthe\sdisk\snot\smemory\nwhile\srunning\sconflict.test.\s\sTicket\s#1453.\s(CVS\s2737)
-D 2005-09-25T01:13:09
+C The\shash\stables\sdeallocate\swhen\sempty\sin\sorder\sto\savoid\snuisanse\scomplaints\nfrom\svalgrind.\s\sAdded\stests\sto\sverify\sno\shash\stable\smemory\sleaks\sin\sos_unix.c.\s(CVS\s2738)
+D 2005-10-03T15:11:09
 F Makefile.in 12784cdce5ffc8dfb707300c34e4f1eb3b8a14f1
 F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -43,7 +43,7 @@ F src/delete.c 29dac493f4d83b05f91233b116827c133bcdab72
 F src/experimental.c 50c1e3b34f752f4ac10c36f287db095c2b61766d
 F src/expr.c bb2cf5d5b065eaa23d5ae2620f6de0568768147d
 F src/func.c f63d417248808ff2632a3b576536abffcc21d858
-F src/hash.c 2b1b13f7400e179631c83a1be0c664608c8f021f
+F src/hash.c 8747cf51d12de46512880dfcf1b68b4e24072863
 F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84
 F src/insert.c 1f51566d7cf4b243a2792f5fda37343d6e9377fa
 F src/legacy.c d58ea507bce885298a2c8c3cbb0f4bff5d47830b
@@ -175,6 +175,7 @@ F test/lock3.test 615111293cf32aa2ed16d01c6611737651c96fb9
 F test/main.test 249f139ef2f75710db1b49bb79e8b27767eacae1
 F test/malloc.test 666c77a878ce50f5c22b9211ed43e889cabb63a6
 F test/malloc2.test 655b972372d2754a3f6c6ed54d7cfd18fde9bd32
+F test/manydb.test 18bc28e481d8e742a767858a8149bc96056aad46
 F test/memdb.test 1860e060be810bf0775bc57408a5b7c4954bcaea
 F test/memleak.test df2b2b96e77f8ba159a332299535b1e5f18e49ac
 F test/minmax.test cad887abca5504396718e2cd5729ca40758743e8
@@ -313,7 +314,7 @@ F www/tclsqlite.tcl ddcf912ea48695603c8ed7efb29f0812ef8d1b49
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P bd141a7c12c779d15d81acc8f919c37b9a4aa40b
-R e99cc461c79342942f21bd434383bc4a
+P 6d780ca6cfbea10d29a4a1b5226efb269606e21a
+R 4faa63c8a1983f974ea848d286400f71
 U drh
-Z cbb7f4db27a540e6257d547caeec74b5
+Z 91a5e6855088b35f854c80b36fa5d6c9
index 65225fcf89c740e6278f0ba82ecf2b601864a854..a808b651364cfa2ea9ca81ed267d87bf122a789d 100644 (file)
@@ -1 +1 @@
-6d780ca6cfbea10d29a4a1b5226efb269606e21a
\ No newline at end of file
+080eadca582a49a069a76ed113ec15e9bce2955a
\ No newline at end of file
index b7b2138da9d9667364cf1ad1ac987dc9535b71b2..2ef86a84f3661687a454b2157b39c7cc5e00a31d 100644 (file)
@@ -12,7 +12,7 @@
 ** 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 <assert.h>
@@ -294,6 +294,11 @@ static void removeElementGivenHash(
   }
   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
diff --git a/test/manydb.test b/test/manydb.test
new file mode 100644 (file)
index 0000000..66af10b
--- /dev/null
@@ -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