From dddb2f23e2c64e08d4216e4a1183ce1e33328549 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 3 Jan 2007 23:37:28 +0000 Subject: [PATCH] Clean up memory leaks and uninitialized variables detected by valgrind. Identify all tests where we deliberately derefence freed memory by adding a "-misuse" tag. (CVS 3550) FossilOrigin-Name: 70a862702d6dfcfe73bdeef8f0502c6c50e32a3a --- manifest | 30 +++++++++++++++--------------- manifest.uuid | 2 +- src/test1.c | 4 ++-- src/test3.c | 3 ++- src/test8.c | 3 ++- src/vacuum.c | 4 ++-- test/btree.test | 3 +-- test/capi2.test | 6 +++--- test/capi3.test | 12 ++++++------ test/conflict.test | 3 ++- test/ioerr.test | 3 ++- test/misc5.test | 4 ++-- 12 files changed, 40 insertions(+), 37 deletions(-) diff --git a/manifest b/manifest index 740e5418cb..1082d9a618 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Additional\schanges\sin\sthe\spager\sand\sos\sinterface\slayers\sto\sfix\sproblems\sthat\nmight\sbe\scontributing\sto\srecently\sobserved\sdatabase\scorruption.\s(CVS\s3549) -D 2007-01-03T23:36:22 +C Clean\sup\smemory\sleaks\sand\suninitialized\svariables\sdetected\sby\svalgrind.\nIdentify\sall\stests\swhere\swe\sdeliberately\sderefence\sfreed\smemory\sby\sadding\na\s"-misuse"\stag.\s(CVS\s3550) +D 2007-01-03T23:37:28 F Makefile.in 63a71177ed4355c829229affe11167bd28c85884 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -100,14 +100,14 @@ F src/sqlite3ext.h 2c2156cc32a158e2b7bd9042d42accf94bff2e40 F src/sqliteInt.h 90dad3c0ba7a5151c48361748ccdada9ff2eff78 F src/table.c 6d0da66dde26ee75614ed8f584a1996467088d06 F src/tclsqlite.c d344c7f394d6f055ce3abfe0049b0480c5e34e56 -F src/test1.c 19786ff3274635b6eac27a89f842416f388f3654 +F src/test1.c 1194cd78dbc5180e0c1a44e6d7eb27577bb9122e F src/test2.c ca74a1d8aeb7d9606e8f6b762c5daf85c1a3f92b -F src/test3.c 85135c09560c48bdb0a23c9b890ab405486b8ec9 +F src/test3.c fa0e85ddd1784f2dda5861a2cb4e7d27d1c932c1 F src/test4.c 8b784cd82de158a2317cb4ac4bc86f91ad315e25 F src/test5.c 7162f8526affb771c4ed256826eee7bb9eca265f F src/test6.c 60a02961ceb7b3edc25f5dc5c1ac2556622a76de F src/test7.c 03fa8d787f6aebc6d1f72504d52f33013ad2c8e3 -F src/test8.c 48b7ac78ca3c93210b7355da94325baa901ecfeb +F src/test8.c 628ec89f9fbf3bfb9c58a503d845a0719595d0ad F src/test_async.c e3deaedd4d86a56391b81808fde9e44fbd92f1d3 F src/test_autoext.c 855157d97aa28cf84233847548bfacda21807436 F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8 @@ -120,7 +120,7 @@ F src/trigger.c 8c55d31876013ed4e97ee7ce24478fbe00db49bb F src/update.c 951f95ef044cf6d28557c48dc35cb0711a0b9129 F src/utf.c 67ecb1032bc0b42c105e88d65ef9d9f626eb0e1f F src/util.c 91d4cb189476906639ae611927d939691d1365f6 -F src/vacuum.c b620ffff5a84af88b970894a92bb330bd2b9fc45 +F src/vacuum.c b4569b08aaa5afb141af3f76d0315745db4e9e4b F src/vdbe.c 15060804371ab78d44a131061ae85c4c66dfff7c F src/vdbe.h 9720cae673359dc2bdcb106285ecf686b7d3ef24 F src/vdbeInt.h 1ca07f2d7446c90230346aed7fbf990c032460bc @@ -158,7 +158,7 @@ F test/bigrow.test f0aeb7573dcb8caaafea76454be3ade29b7fc747 F test/bind.test 941a424e7722dd8994c2d503b28d00e6a8f87f23 F test/bindxfer.test b76bfb7df68bb0b238039f4543a84e9612291b54 F test/blob.test 28c3b25150684ee3d108bb78cfb67a472deef2f0 -F test/btree.test 099978c3b9f0a203f4805d2bb8fdb042d5cb8ffc +F test/btree.test 5902dd2dc3aff942726b32e1d437bc8227b6c3c5 F test/btree2.test 4b56a2a4a4f84d68c77aef271223a713bf5ebafc F test/btree4.test 3797b4305694c7af6828675b0f4b1424b8ca30e4 F test/btree5.test 8e5ff32c02e685d36516c6499add9375fe1377f2 @@ -166,8 +166,8 @@ F test/btree6.test a5ede6bfbbb2ec8b27e62813612c0f28e8f3e027 F test/btree7.test a6d3b842db22af97dd14b989e90a2fd96066b72f F test/btree8.test fadc112bcbd6a0c622d34c813fc8a648eacf8804 F test/busy.test 0271c854738e23ad76e10d4096a698e5af29d211 -F test/capi2.test cb478885b8b1a6a9f703a9da1c8d7d101c0970d6 -F test/capi3.test 5f54824e8356ad25ee40a101b36452e74d68a945 +F test/capi2.test 7ecc9b342cc9ec27b53bbf95724cf2e5874fd496 +F test/capi3.test 4063c4be79fb00704154a1e459a38364de9162a9 F test/capi3b.test 5f0bc94b104e11086b1103b20277e1910f59c7f4 F test/capi3c.test d45ecc2e06879967a6a0786dff1caa2195f08ac1 F test/cast.test f88e7b6946e9a467cf4bb142d92bb65a83747fc2 @@ -179,7 +179,7 @@ F test/collate4.test daf498e294dcd596b961d425c3f2dda117e4717e F test/collate5.test 8fb4e7e0241839356bd8710f437c32efb47bfff8 F test/collate6.test 6c9470d1606ee3e564675b229653e320c49ec638 F test/colmeta.test 6505c73ab58796afcb7c89ba9f429d573fbc6e53 -F test/conflict.test 16533a92675f9752c25596093a4d549af7fc3d34 +F test/conflict.test 8a59399f61a14296a9bfed02e0570590a8a79cba F test/corrupt.test 18c7a995b1af76a8c8600b996257f2c7b7bff083 F test/corrupt2.test 88342570828f2b8cbbd8369eff3891f5c0bdd5ba F test/crash.test 5f5f155393c5685b3842fef79b6fbafa55197d75 @@ -226,7 +226,7 @@ F test/insert2.test 5a20e1ace5fa0800b58d28284212290189b49aed F test/insert3.test 09a532d5b6f3a788d91be0d4d368462f522685d1 F test/interrupt.test c38b7f7c17914f0cd6a119beed5d03bc3f47f9eb F test/intpkey.test af4fd826c4784ec5c93b444de07adea0254d0d30 -F test/ioerr.test 6f67d9328a3909dc43b1f66864f7fbc7fd399812 +F test/ioerr.test 58fb371922c4c220e4794397c17e32465cacc6de F test/join.test af0443185378b64878750aa1cf4b83c216f246b4 F test/join2.test f2171c265e57ee298a27e57e7051d22962f9f324 F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0 @@ -258,7 +258,7 @@ F test/misc1.test 27a6ad11ba6e4b73aeee650ab68053ad7dfd0433 F test/misc2.test 0b45deedcfd6ba857ea2f377c5669d3501a535c7 F test/misc3.test 7bd937e2c62bcc6be71939faf068d506467b1e03 F test/misc4.test b043a05dea037cca5989f3ae09552fa16119bc80 -F test/misc5.test 83bceca3d38ed10ced00271e02b26b24795def83 +F test/misc5.test c7d2d2a5a20dc37d3605a8067f0df5af2240122e F test/misc6.test 3de55ec5cadf466ada587173faa5d6a4790a8bb7 F test/misuse.test 30b3a458e5a70c31e74c291937b6c82204c59f33 F test/notnull.test 44d600f916b770def8b095a9962dbe3be5a70d82 @@ -423,7 +423,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 -P 6806b9ecb5e3b90e793c5862404e76485df33b25 -R 5eb75b3bfe211ed1d7c750440df7692b +P a593d5743eab12c0f93a7bc436f0d69dfab0c387 +R 908ed5b0eff5f1c974f45bd56e3c693e U drh -Z bcb83f017e9e848c1a261f1dbdf86d77 +Z cb8e6cfd19833bef1e1d27957c41fff4 diff --git a/manifest.uuid b/manifest.uuid index e1d031331c..659e024312 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a593d5743eab12c0f93a7bc436f0d69dfab0c387 \ No newline at end of file +70a862702d6dfcfe73bdeef8f0502c6c50e32a3a \ No newline at end of file diff --git a/src/test1.c b/src/test1.c index 3cb00e3b81..ab961d4482 100644 --- a/src/test1.c +++ b/src/test1.c @@ -13,7 +13,7 @@ ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test1.c,v 1.225 2006/11/23 09:39:16 drh Exp $ +** $Id: test1.c,v 1.226 2007/01/03 23:37:28 drh Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -1415,7 +1415,7 @@ static int test_finalize( ){ sqlite3_stmt *pStmt; int rc; - sqlite3 *db; + sqlite3 *db = 0; if( objc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", diff --git a/src/test3.c b/src/test3.c index d982380408..4f42b5fbfd 100644 --- a/src/test3.c +++ b/src/test3.c @@ -13,7 +13,7 @@ ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test3.c,v 1.67 2006/08/13 18:39:26 drh Exp $ +** $Id: test3.c,v 1.68 2007/01/03 23:37:28 drh Exp $ */ #include "sqliteInt.h" #include "pager.h" @@ -1051,6 +1051,7 @@ static int btree_data( rc = sqlite3BtreeData(pCur, 0, n, zBuf); if( rc ){ Tcl_AppendResult(interp, errorName(rc), 0); + free(zBuf); return TCL_ERROR; } zBuf[n] = 0; diff --git a/src/test8.c b/src/test8.c index 92ca8e27e4..36465afd09 100644 --- a/src/test8.c +++ b/src/test8.c @@ -13,7 +13,7 @@ ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test8.c,v 1.43 2006/10/08 18:56:57 drh Exp $ +** $Id: test8.c,v 1.44 2007/01/03 23:37:29 drh Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -639,6 +639,7 @@ static int echoBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){ */ zQuery = sqlite3_mprintf("SELECT count(*) FROM %Q", pVtab->zTableName); rc = sqlite3_prepare(pVtab->db, zQuery, -1, &pStmt, 0); + sqlite3_free(zQuery); if( rc!=SQLITE_OK ){ return rc; } diff --git a/src/vacuum.c b/src/vacuum.c index 510390a010..77d99461ea 100644 --- a/src/vacuum.c +++ b/src/vacuum.c @@ -14,7 +14,7 @@ ** Most of the code in this file may be omitted by defining the ** SQLITE_OMIT_VACUUM macro. ** -** $Id: vacuum.c,v 1.65 2006/11/18 20:20:22 drh Exp $ +** $Id: vacuum.c,v 1.66 2007/01/03 23:37:29 drh Exp $ */ #include "sqliteInt.h" #include "vdbeInt.h" @@ -89,6 +89,7 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){ saved_flags = db->flags; db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks; + sqlite3OsTempFileName(zTemp); if( !db->autoCommit ){ sqlite3SetString(pzErrMsg, "cannot VACUUM from within a transaction", (char*)0); @@ -96,7 +97,6 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){ goto end_of_vacuum; } pMain = db->aDb[0].pBt; - sqlite3OsTempFileName(zTemp); /* Attach the temporary database as 'vacuum_db'. The synchronous pragma ** can be set to 'off' for this file, as it is not recovered if a crash diff --git a/test/btree.test b/test/btree.test index 8d440aebde..1bb8226a57 100644 --- a/test/btree.test +++ b/test/btree.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this script is btree database backend # -# $Id: btree.test,v 1.37 2006/08/16 16:42:48 drh Exp $ +# $Id: btree.test,v 1.38 2007/01/03 23:37:29 drh Exp $ set testdir [file dirname $argv0] @@ -548,7 +548,6 @@ do_test btree-8.1 { } {} btree_page_dump $::b1 1 btree_page_dump $::b1 2 -btree_page_dump $::b1 3 do_test btree-8.1.1 { lindex [btree_pager_stats $::b1] 1 } {1} diff --git a/test/capi2.test b/test/capi2.test index dc7182cf3b..971d6acb40 100644 --- a/test/capi2.test +++ b/test/capi2.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this script testing the callback-free C/C++ API. # -# $Id: capi2.test,v 1.32 2006/08/16 16:42:48 drh Exp $ +# $Id: capi2.test,v 1.33 2007/01/03 23:37:29 drh Exp $ # set testdir [file dirname $argv0] @@ -71,7 +71,7 @@ do_test capi2-1.6 { do_test capi2-1.7 { list [sqlite3_column_count $VM] [get_row_values $VM] [get_column_names $VM] } {2 {} {name rowid text INTEGER}} -do_test capi2-1.8 { +do_test capi2-1.8-misuse { sqlite3_step $VM } {SQLITE_MISUSE} @@ -208,7 +208,7 @@ do_test capi2-3.11 { sqlite3_finalize $VM } {SQLITE_OK} do_test capi2-3.11b {db changes} {1} -do_test capi2-3.12 { +do_test capi2-3.12-misuse { sqlite3_finalize $VM } {SQLITE_MISUSE} do_test capi2-3.13 { diff --git a/test/capi3.test b/test/capi3.test index 35b7468042..9b24ea8b74 100644 --- a/test/capi3.test +++ b/test/capi3.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this script testing the callback-free C/C++ API. # -# $Id: capi3.test,v 1.46 2006/08/16 16:42:48 drh Exp $ +# $Id: capi3.test,v 1.47 2007/01/03 23:37:29 drh Exp $ # set testdir [file dirname $argv0] @@ -152,14 +152,14 @@ do_test capi3-3.4 { do_test capi3-3.5 { sqlite3_close $db2 } {SQLITE_OK} -do_test capi3-3.6.1 { +do_test capi3-3.6.1-misuse { sqlite3_close $db2 } {SQLITE_MISUSE} -do_test capi3-3.6.2 { +do_test capi3-3.6.2-misuse { sqlite3_errmsg $db2 } {library routine called out of sequence} ifcapable {utf16} { - do_test capi3-3.6.3 { + do_test capi3-3.6.3-misuse { utf8 [sqlite3_errmsg16 $db2] } {library routine called out of sequence} } @@ -612,7 +612,7 @@ check_data $STMT capi3-6.3 {INTEGER} {1} {1.0} {1} do_test capi3-6.3 { sqlite3_finalize $STMT } {SQLITE_OK} -do_test capi3-6.4 { +do_test capi3-6.4-misuse { db cache flush sqlite3_close $DB } {SQLITE_OK} @@ -991,7 +991,7 @@ if {[llength [info commands sqlite3_sleep]]>0} { # Ticket #1219: Make sure binding APIs can handle a NULL pointer. # -do_test capi3-14.1 { +do_test capi3-14.1-misuse { set rc [catch {sqlite3_bind_text 0 1 hello 5} msg] lappend rc $msg } {1 SQLITE_MISUSE} diff --git a/test/conflict.test b/test/conflict.test index 408417be42..cc002c629a 100644 --- a/test/conflict.test +++ b/test/conflict.test @@ -13,7 +13,7 @@ # This file implements tests for the conflict resolution extension # to SQLite. # -# $Id: conflict.test,v 1.27 2006/01/17 09:35:02 danielk1977 Exp $ +# $Id: conflict.test,v 1.28 2007/01/03 23:37:29 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -309,6 +309,7 @@ foreach {i conf1 cmd t0 t1 t2 t3} { if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"} execsql {pragma temp_store=file} set ::sqlite_opentemp_count 0 +if {$i==2} btree_breakpoint set r0 [catch {execsql [subst { DROP TABLE t1; CREATE TABLE t1(a,b,c, UNIQUE(a) $conf1); diff --git a/test/ioerr.test b/test/ioerr.test index 8f1088225c..49c8bb3229 100644 --- a/test/ioerr.test +++ b/test/ioerr.test @@ -15,7 +15,7 @@ # The tests in this file use special facilities that are only # available in the SQLite test fixture. # -# $Id: ioerr.test,v 1.27 2006/09/15 07:28:51 drh Exp $ +# $Id: ioerr.test,v 1.28 2007/01/03 23:37:29 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -165,6 +165,7 @@ ifcapable crashtest { # These tests can't be run on windows because the windows version of # SQLite holds a mandatory exclusive lock on journal files it has open. # +btree_breakpoint if {$tcl_platform(platform)!="windows"} { do_ioerr_test ioerr-7 -tclprep { db close diff --git a/test/misc5.test b/test/misc5.test index 98060a554a..fcb91942b4 100644 --- a/test/misc5.test +++ b/test/misc5.test @@ -13,7 +13,7 @@ # This file implements tests for miscellanous features that were # left out of other test files. # -# $Id: misc5.test,v 1.15 2006/08/12 12:33:15 drh Exp $ +# $Id: misc5.test,v 1.16 2007/01/03 23:37:29 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -573,7 +573,7 @@ do_test misc5-7.1 { # Check the MISUSE return from sqlitee3_busy_timeout # -do_test misc5-8.1 { +do_test misc5-8.1-misuse { set DB [sqlite3_connection_pointer db] db close sqlite3_busy_timeout $DB 1000 -- 2.47.2