SQLite

Check-in [7d3f0b149b]
Login

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

Overview
Comment:Add a test case to malloc.test. (CVS 4456)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 7d3f0b149bd2b9c7c12aabb93d022c0ea26f0d74
User & Date: danielk1977 2007-10-03 15:02:40.000
Context
2007-10-03
15:22
Fix a memory leak that could occur during error-state recovery. (CVS 4457) (check-in: 3d1d13d1eb user: danielk1977 tags: trunk)
15:02
Add a test case to malloc.test. (CVS 4456) (check-in: 7d3f0b149b user: danielk1977 tags: trunk)
09:43
Fix a problem in test script malloc5.test. (CVS 4455) (check-in: 028ec36c71 user: danielk1977 tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to test/malloc.test.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# This file attempts to check the behavior of the SQLite library in 
# an out-of-memory situation. When compiled with -DSQLITE_DEBUG=1, 
# 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.49 2007/10/03 08:46:45 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Only run these tests if memory debugging is turned on.
#
ifcapable !memdebug {







|







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# This file attempts to check the behavior of the SQLite library in 
# an out-of-memory situation. When compiled with -DSQLITE_DEBUG=1, 
# 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.50 2007/10/03 15:02:40 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Only run these tests if memory debugging is turned on.
#
ifcapable !memdebug {
515
516
517
518
519
520
521









































522
523
524
525
526
527
528
529
530
  if {$r} {error [string range $msg 4 end]}
} -cleanup {
  if {$::STMT ne ""} {
    sqlite3_finalize $::STMT
    set ::STMT ""
  }
}










































# 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







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>









515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
  if {$r} {error [string range $msg 4 end]}
} -cleanup {
  if {$::STMT ne ""} {
    sqlite3_finalize $::STMT
    set ::STMT ""
  }
}

ifcapable {pager_pragmas} {
  # This tests a special case - that an error that occurs while the pager
  # is trying to recover from error-state in exclusive-access mode works.
  #
  do_malloc_test 23 -tclprep {
    db eval {
      PRAGMA cache_size = 10;
      PRAGMA locking_mode = exclusive;
      BEGIN;
      CREATE TABLE abc(a, b, c);
      CREATE INDEX abc_i ON abc(a, b, c);
      INSERT INTO abc 
        VALUES(randstr(100,100), randstr(100,100), randstr(100,100));
      INSERT INTO abc 
        SELECT randstr(100,100), randstr(100,100), randstr(100,100) FROM abc;
      INSERT INTO abc 
        SELECT randstr(100,100), randstr(100,100), randstr(100,100) FROM abc;
      INSERT INTO abc 
        SELECT randstr(100,100), randstr(100,100), randstr(100,100) FROM abc;
      INSERT INTO abc 
        SELECT randstr(100,100), randstr(100,100), randstr(100,100) FROM abc;
      INSERT INTO abc 
        SELECT randstr(100,100), randstr(100,100), randstr(100,100) FROM abc;
      COMMIT;
    }
  
    # This puts the pager into error state.
    #
    db eval BEGIN
    db eval {UPDATE abc SET a = 0 WHERE oid%2}
    set ::sqlite_io_error_pending 10
    catch {db eval {ROLLBACK}} msg

  } -sqlbody {
    SELECT * FROM abc LIMIT 10;
  } -cleanup {
    set e [db eval {PRAGMA integrity_check}]
    if {$e ne "ok"} {error $e}
  }
}

# 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