Fix a memory leak that can occur in os_unix.c if an IO error occurs within the xUnlock method.
FossilOrigin-Name: 6c5c04eea1f0e8d61883ee8675c249fbf895dc01
This commit is contained in:
+15
-22
@@ -109,36 +109,29 @@ proc do_faultsim_test {name args} {
|
||||
#-------------------------------------------------------------------------
|
||||
# Procedures to save and restore the current file-system state:
|
||||
#
|
||||
# faultsim_save
|
||||
# faultsim_save_and_close
|
||||
# faultsim_restore_and_reopen
|
||||
# faultsim_delete_and_reopen
|
||||
#
|
||||
proc faultsim_save_and_close {} {
|
||||
foreach {a => b} {
|
||||
test.db => testX.db
|
||||
test.db-wal => testX.db-wal
|
||||
test.db-journal => testX.db-journal
|
||||
} {
|
||||
if {[file exists $a]} {
|
||||
file copy -force $a $b
|
||||
} else {
|
||||
file delete -force $b
|
||||
}
|
||||
proc faultsim_save {} {
|
||||
foreach f [glob -nocomplain sv_test.db*] { file delete -force $f }
|
||||
foreach f [glob -nocomplain test.db*] {
|
||||
set f2 "sv_$f"
|
||||
file copy -force $f $f2
|
||||
}
|
||||
}
|
||||
proc faultsim_save_and_close {} {
|
||||
faultsim_save
|
||||
catch { db close }
|
||||
return ""
|
||||
}
|
||||
proc faultsim_restore_and_reopen {} {
|
||||
catch { db close }
|
||||
foreach {a => b} {
|
||||
testX.db => test.db
|
||||
testX.db-wal => test.db-wal
|
||||
testX.db-journal => test.db-journal
|
||||
} {
|
||||
if {[file exists $a]} {
|
||||
file copy -force $a $b
|
||||
} else {
|
||||
file delete -force $b
|
||||
}
|
||||
foreach f [glob -nocomplain test.db*] { file delete -force $f }
|
||||
foreach f2 [glob -nocomplain sv_test.db*] {
|
||||
set f [string range $f2 3 end]
|
||||
file copy -force $f2 $f
|
||||
}
|
||||
sqlite3 db test.db
|
||||
sqlite3_extended_result_codes db 1
|
||||
@@ -152,7 +145,7 @@ proc faultsim_integrity_check {{db db}} {
|
||||
|
||||
proc faultsim_delete_and_reopen {{file test.db}} {
|
||||
catch { db close }
|
||||
file delete -force test.db test.db-wal test.db-journal
|
||||
foreach f [glob -nocomplain test.db*] { file delete -force $f }
|
||||
sqlite3 db test.db
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,21 @@ source $testdir/tester.tcl
|
||||
source $testdir/lock_common.tcl
|
||||
source $testdir/malloc_common.tcl
|
||||
|
||||
#
|
||||
# pager1-1.*: Test inter-process locking (clients in multiple processes).
|
||||
#
|
||||
# pager1-2.*: Test intra-process locking (multiple clients in this process).
|
||||
#
|
||||
# pager1-3.*: Savepoint related tests.
|
||||
#
|
||||
|
||||
proc do_execsql_test {testname sql result} {
|
||||
uplevel do_test $testname [list "execsql {$sql}"] [list $result]
|
||||
}
|
||||
proc do_catchsql_test {testname sql result} {
|
||||
uplevel do_test $testname [list "catchsql {$sql}"] [list $result]
|
||||
}
|
||||
|
||||
do_multiclient_test tn {
|
||||
|
||||
# Create and populate a database table using connection [db]. Check
|
||||
@@ -151,5 +166,38 @@ do_multiclient_test tn {
|
||||
do_test pager1-$tn.28 { sql3 { SELECT * FROM t1 } } {21 one 22 two 23 three}
|
||||
}
|
||||
|
||||
do_test pager1-3.1 {
|
||||
faultsim_delete_and_reopen
|
||||
execsql {
|
||||
CREATE TABLE t1(a PRIMARY KEY, b);
|
||||
CREATE TABLE counter(
|
||||
i CHECK (i<5),
|
||||
u CHECK (u<10)
|
||||
);
|
||||
INSERT INTO counter VALUES(0, 0);
|
||||
CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN
|
||||
UPDATE counter SET i = i+1;
|
||||
END;
|
||||
CREATE TRIGGER tr2 AFTER UPDATE ON t1 BEGIN
|
||||
UPDATE counter SET u = u+1;
|
||||
END;
|
||||
}
|
||||
execsql { SELECT * FROM counter }
|
||||
} {0 0}
|
||||
|
||||
do_execsql_test pager1-3.2 {
|
||||
BEGIN;
|
||||
INSERT INTO t1 VALUES(1, randomblob(1500));
|
||||
INSERT INTO t1 VALUES(2, randomblob(1500));
|
||||
INSERT INTO t1 VALUES(3, randomblob(1500));
|
||||
SELECT * FROM counter;
|
||||
} {3 0}
|
||||
do_catchsql_test pager1-3.3 {
|
||||
INSERT INTO t1 SELECT a+3, randomblob(1500) FROM t1
|
||||
} {1 {constraint failed}}
|
||||
do_execsql_test pager1-3.4 { SELECT * FROM counter } {3 0}
|
||||
do_execsql_test pager1-3.5 { SELECT a FROM t1 } {1 2 3}
|
||||
do_execsql_test pager1-3.6 { COMMIT } {}
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
# 2010 June 15
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
source $testdir/lock_common.tcl
|
||||
source $testdir/malloc_common.tcl
|
||||
|
||||
set a_string_counter 1
|
||||
proc a_string {n} {
|
||||
global a_string_counter
|
||||
incr a_string_counter
|
||||
string range [string repeat "${a_string_counter}." $n] 1 $n
|
||||
}
|
||||
db func a_string a_string
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Test fault-injection while rolling back a hot-journal file.
|
||||
#
|
||||
do_test pagerfault-1-pre1 {
|
||||
execsql {
|
||||
PRAGMA journal_mode = DELETE;
|
||||
PRAGMA cache_size = 10;
|
||||
CREATE TABLE t1(a UNIQUE, b UNIQUE);
|
||||
INSERT INTO t1 VALUES(a_string(200), a_string(300));
|
||||
INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
|
||||
INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
|
||||
BEGIN;
|
||||
INSERT INTO t1 SELECT a_string(201), a_string(301) FROM t1;
|
||||
INSERT INTO t1 SELECT a_string(202), a_string(302) FROM t1;
|
||||
INSERT INTO t1 SELECT a_string(203), a_string(303) FROM t1;
|
||||
INSERT INTO t1 SELECT a_string(204), a_string(304) FROM t1;
|
||||
}
|
||||
faultsim_save_and_close
|
||||
} {}
|
||||
do_faultsim_test pagerfault-1 -prep {
|
||||
faultsim_restore_and_reopen
|
||||
} -body {
|
||||
execsql { SELECT count(*) FROM t1 }
|
||||
} -test {
|
||||
faultsim_test_result {0 4}
|
||||
faultsim_integrity_check
|
||||
if {[db one { SELECT count(*) FROM t1 }] != 4} {
|
||||
error "Database content appears incorrect"
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Test fault-injection while rolling back hot-journals that were created
|
||||
# as part of a multi-file transaction.
|
||||
#
|
||||
do_test pagerfault-2-pre1 {
|
||||
testvfs tstvfs -default 1
|
||||
tstvfs filter xDelete
|
||||
tstvfs script xDeleteCallback
|
||||
|
||||
proc xDeleteCallback {method file args} {
|
||||
set file [file tail $file]
|
||||
if { [string match *mj* $file] } { faultsim_save }
|
||||
}
|
||||
|
||||
faultsim_delete_and_reopen
|
||||
db func a_string a_string
|
||||
|
||||
execsql {
|
||||
ATTACH 'test.db2' AS aux;
|
||||
PRAGMA journal_mode = DELETE;
|
||||
PRAGMA main.cache_size = 10;
|
||||
PRAGMA aux.cache_size = 10;
|
||||
|
||||
CREATE TABLE t1(a UNIQUE, b UNIQUE);
|
||||
CREATE TABLE aux.t2(a UNIQUE, b UNIQUE);
|
||||
INSERT INTO t1 VALUES(a_string(200), a_string(300));
|
||||
INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
|
||||
INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
|
||||
INSERT INTO t2 SELECT * FROM t1;
|
||||
|
||||
BEGIN;
|
||||
INSERT INTO t1 SELECT a_string(201), a_string(301) FROM t1;
|
||||
INSERT INTO t1 SELECT a_string(202), a_string(302) FROM t1;
|
||||
INSERT INTO t1 SELECT a_string(203), a_string(303) FROM t1;
|
||||
INSERT INTO t1 SELECT a_string(204), a_string(304) FROM t1;
|
||||
REPLACE INTO t2 SELECT * FROM t1;
|
||||
COMMIT;
|
||||
}
|
||||
|
||||
db close
|
||||
tstvfs delete
|
||||
} {}
|
||||
do_faultsim_test pagerfault-2 -faults ioerr-persistent -prep {
|
||||
faultsim_restore_and_reopen
|
||||
} -body {
|
||||
execsql {
|
||||
ATTACH 'test.db2' AS aux;
|
||||
SELECT count(*) FROM t2;
|
||||
SELECT count(*) FROM t1;
|
||||
}
|
||||
} -test {
|
||||
faultsim_test_result {0 {4 4}} {1 {unable to open database: test.db2}}
|
||||
faultsim_integrity_check
|
||||
|
||||
catchsql { ATTACH 'test.db2' AS aux }
|
||||
if {[db one { SELECT count(*) FROM t1 }] != 4
|
||||
|| [db one { SELECT count(*) FROM t2 }] != 4
|
||||
} {
|
||||
error "Database content appears incorrect"
|
||||
}
|
||||
}
|
||||
|
||||
finish_test
|
||||
@@ -169,6 +169,7 @@ test_suite "coverage-pager" -description {
|
||||
Coverage tests for file pager.c.
|
||||
} -files {
|
||||
pager1.test
|
||||
pagerfault.test
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user