1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Fix some places where a malloc() failure would lead to a segfault. (CVS 580)

FossilOrigin-Name: 01ad352c3c82a86d9c94010cbc85d098b8fbc08a
This commit is contained in:
drh
2002-05-23 02:09:03 +00:00
parent 1873cd508a
commit e4697f5e90
7 changed files with 77 additions and 33 deletions

View File

@ -14,7 +14,7 @@
# 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.4 2001/10/22 02:58:11 drh Exp $
# $Id: malloc.test,v 1.5 2002/05/23 02:09:05 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -65,10 +65,6 @@ for {set go 1; set i 1} {$go} {incr i} {
} {1 1}
}
finish_test
return
set fd [open ./data.tmp w]
for {set i 1} {$i<=20} {incr i} {
puts $fd "$i\t[expr {$i*$i}]\t[expr {100-$i}] abcdefghijklmnopqrstuvwxyz"
@ -191,5 +187,39 @@ for {set go 1; set i 1} {$go} {incr i} {
}
} {1 1}
}
for {set go 1; set i 1} {$go} {incr i} {
do_test malloc-5.$i {
sqlite_malloc_fail 0
catch {db close}
catch {file delete -force test.db}
catch {file delete -force test.db-journal}
sqlite_malloc_fail $i
set v [catch {sqlite db test.db} msg]
if {$v} {
set msg ""
} else {
set v [catch {execsql {
BEGIN TRANSACTION;
CREATE TABLE t1(a,b);
CREATE TABLE t2(x,y);
CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN
INSERT INTO t2(x,y) VALUES(new.rowid,1);
END;
INSERT INTO t1(a,b) VALUES(2,3);
COMMIT;
}} msg]
}
set leftover [lindex [sqlite_malloc_stat] 2]
if {$leftover>0} {
if {$leftover>1} {puts "\nLeftover: $leftover\nReturn=$v Message=$msg"}
set ::go 0
set v {1 1}
} else {
set v2 [expr {$msg=="" || $msg=="out of memory"}]
if {!$v2} {puts "\nError message returned: $msg"}
lappend v $v2
}
} {1 1}
}
sqlite_malloc_fail 0
finish_test