xref: /sqlite-3.40.0/test/malloc9.test (revision eee4c8ca)
1276fdbfdSdrh# 2007 April 30
2276fdbfdSdrh#
3276fdbfdSdrh# The author disclaims copyright to this source code.  In place of
4276fdbfdSdrh# a legal notice, here is a blessing:
5276fdbfdSdrh#
6276fdbfdSdrh#    May you do good and not evil.
7276fdbfdSdrh#    May you find forgiveness for yourself and forgive others.
8276fdbfdSdrh#    May you share freely, never taking more than you give.
9276fdbfdSdrh#
10276fdbfdSdrh#***********************************************************************
11276fdbfdSdrh# This file contains additional out-of-memory checks (see malloc.tcl)
12276fdbfdSdrh# added to expose a bug in out-of-memory handling for sqlite3_prepare().
13276fdbfdSdrh#
14*eee4c8caSdrh# $Id: malloc9.test,v 1.4 2008/02/18 22:24:58 drh Exp $
15276fdbfdSdrh
16276fdbfdSdrhset testdir [file dirname $argv0]
17276fdbfdSdrhsource $testdir/tester.tcl
18*eee4c8caSdrhsource $testdir/malloc_common.tcl
19276fdbfdSdrh
20276fdbfdSdrh# Only run these tests if memory debugging is turned on.
21276fdbfdSdrh#
22*eee4c8caSdrhif {!$MEMDEBUG} {
235a3032b3Sdrh   puts "Skipping malloc9 tests: not compiled with -DSQLITE_MEMDEBUG..."
24276fdbfdSdrh   finish_test
25276fdbfdSdrh   return
26276fdbfdSdrh}
27276fdbfdSdrh
28276fdbfdSdrh
29276fdbfdSdrhdo_malloc_test 1 -tclprep {
30276fdbfdSdrh  set sql {CREATE TABLE t1(x)}
31276fdbfdSdrh  set sqlbytes [string length $sql]
32276fdbfdSdrh  append sql {; INSERT INTO t1 VALUES(1)}
33276fdbfdSdrh} -tclbody {
34276fdbfdSdrh  if {[catch {sqlite3_prepare db $sql $sqlbytes TAIL} STMT]} {
35276fdbfdSdrh    set msg $STMT
36276fdbfdSdrh    set STMT {}
37276fdbfdSdrh    error $msg
38276fdbfdSdrh  }
39276fdbfdSdrh} -cleanup {
40276fdbfdSdrh  if {$STMT!=""} {
41276fdbfdSdrh    sqlite3_finalize $STMT
42276fdbfdSdrh  }
43276fdbfdSdrh}
44276fdbfdSdrh
45276fdbfdSdrh# Ensure that no file descriptors were leaked.
46276fdbfdSdrhdo_test malloc-99.X {
47276fdbfdSdrh  catch {db close}
48276fdbfdSdrh  set sqlite_open_file_count
49276fdbfdSdrh} {0}
50276fdbfdSdrh
51276fdbfdSdrhfinish_test
52