/ Check-in [080eadca]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:The hash tables deallocate when empty in order to avoid nuisanse complaints from valgrind. Added tests to verify no hash table memory leaks in os_unix.c. (CVS 2738)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 080eadca582a49a069a76ed113ec15e9bce2955a
User & Date: drh 2005-10-03 15:11:09
Context
2005-10-04
18:38
Automatically check for the fdatasync() function and replace it with fsync() if not found. (CVS 2739) check-in: 385a08af user: drh tags: trunk
2005-10-03
15:11
The hash tables deallocate when empty in order to avoid nuisanse complaints from valgrind. Added tests to verify no hash table memory leaks in os_unix.c. (CVS 2738) check-in: 080eadca user: drh tags: trunk
2005-09-25
01:13
Make sure the default storage for virtual tables is the disk not memory while running conflict.test. Ticket #1453. (CVS 2737) check-in: 6d780ca6 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/hash.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This is the implementation of generic hash-tables
    13     13   ** used in SQLite.
    14     14   **
    15         -** $Id: hash.c,v 1.16 2005/01/31 12:56:44 danielk1977 Exp $
           15  +** $Id: hash.c,v 1.17 2005/10/03 15:11:09 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #include <assert.h>
    19     19   
    20     20   /* Turn bulk memory into a hash table object by initializing the
    21     21   ** fields of the Hash structure.
    22     22   **
................................................................................
   290    290       pEntry->chain = 0;
   291    291     }
   292    292     if( pH->copyKey && elem->pKey ){
   293    293       sqliteFree(elem->pKey);
   294    294     }
   295    295     sqliteFree( elem );
   296    296     pH->count--;
          297  +  if( pH->count<=0 ){
          298  +    assert( pH->first==0 );
          299  +    assert( pH->count==0 );
          300  +    sqlite3HashClear(pH);
          301  +  }
   297    302   }
   298    303   
   299    304   /* Attempt to locate an element of the hash table pH with a key
   300    305   ** that matches pKey,nKey.  Return the data for this element if it is
   301    306   ** found, or NULL if there is no match.
   302    307   */
   303    308   void *sqlite3HashFind(const Hash *pH, const void *pKey, int nKey){

Added test/manydb.test.

            1  +# 2005 October 3
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# This file implements regression tests for SQLite library.
           12  +#
           13  +# This file implements tests the ability of the library to open
           14  +# many different databases at the same time without leaking memory.
           15  +#
           16  +# $Id: manydb.test,v 1.1 2005/10/03 15:11:09 drh Exp $
           17  +
           18  +set testdir [file dirname $argv0]
           19  +source $testdir/tester.tcl
           20  +
           21  +set N 300
           22  +
           23  +# Create a bunch of random database names
           24  +#
           25  +unset -nocomplain dbname
           26  +unset -nocomplain used
           27  +for {set i 0} {$i<$N} {incr i} {
           28  +  while 1 {
           29  +    set name test-[format %08x [expr {int(rand()*0x7fffffff)}]].db
           30  +    if {[info exists used($name)]} continue
           31  +    set dbname($i) $name
           32  +    set used($name) $i
           33  +    break
           34  +  }
           35  +}
           36  +
           37  +# Create a bunch of databases
           38  +#
           39  +for {set i 0} {$i<$N} {incr i} {
           40  +  do_test manydb-1.$i {
           41  +    sqlite3 db$i $dbname($i)
           42  +    execsql {
           43  +       CREATE TABLE t1(a,b);
           44  +       BEGIN;
           45  +       INSERT INTO t1 VALUES(1,2);
           46  +    } db$i
           47  +  } {}
           48  +}
           49  +
           50  +# Finish the transactions
           51  +#
           52  +for {set i 0} {$i<$N} {incr i} {
           53  +  do_test manydb-2.$i {
           54  +    execsql {
           55  +       COMMIT;
           56  +       SELECT * FROM t1;
           57  +    } db$i
           58  +  } {1 2}
           59  +}
           60  +
           61  +
           62  +# Close the databases and erase the files.
           63  +#
           64  +for {set i 0} {$i<$N} {incr i} {
           65  +  do_test manydb-3.$i {
           66  +    db$i close
           67  +    file delete -force $dbname($i)
           68  +  } {}
           69  +}
           70  +
           71  +
           72  +
           73  +
           74  +finish_test