]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Simplify .import leak plug and arrange for CLI to be run under valgrind.
authorlarrybr <larrybr@noemail.net>
Mon, 9 May 2022 12:29:47 +0000 (12:29 +0000)
committerlarrybr <larrybr@noemail.net>
Mon, 9 May 2022 12:29:47 +0000 (12:29 +0000)
FossilOrigin-Name: 0d3e2380197aa3e725591266acaeb0d43a7e794ca9153e6c56253cdcf60720b1

manifest
manifest.uuid
src/shell.c.in
test/shell1.test
test/shell3.test
test/shell4.test
test/shell5.test
test/shell8.test
test/tester.tcl

index 7ac50b6a3c1d012e45d81e01060f832bd5777b89..54db67c2c8244b64b4bf948b9ec313a4a7e6b8b9 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Stop\sa\smemory\sleak\sin\s.import,\sand\sadd\sleak\scomplaint\sto\sCLI\sdebug\sbuilds.
-D 2022-05-07T03:53:14.691
+C Simplify\s.import\sleak\splug\sand\sarrange\sfor\sCLI\sto\sbe\srun\sunder\svalgrind.
+D 2022-05-09T12:29:47.606
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -554,7 +554,7 @@ F src/random.c 097dc8b31b8fba5a9aca1697aeb9fd82078ec91be734c16bffda620ced7ab83c
 F src/resolve.c e9ee235c4151d2b7fa47435a219bfd30bf516a804d2f004639858087ebf3137b
 F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
 F src/select.c 151adca2c9ea6f51215e4351bb8eb4f0012bf98c3d5a5c991d4a019c7cbb143e
-F src/shell.c.in 6b7ddce6ebfb52633236c174928f84558fa7471eed99ce189014d40df990c97b
+F src/shell.c.in 0ad33896c3e79a9578c507c8f0589290cbc98b0af1f31ca0cf8ddbb7601e60ef
 F src/sqlite.h.in 2a35f62185eb5e7ecc64a2f68442b538ce9be74f80f28a00abc24837edcf1c17
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
 F src/sqlite3ext.h f49e28c25bd941e79794db5415fdf7b202deb3bc072ed6f1ed273d578703684e
@@ -1397,14 +1397,14 @@ F test/sharedA.test 49d87ec54ab640fbbc3786ee3c01de94aaa482a3a9f834ad3fe92770eb69
 F test/sharedB.test 16cc7178e20965d75278f410943109b77b2e645e
 F test/shared_err.test 32634e404a3317eeb94abc7a099c556a346fdb8fb3858dbe222a4cbb8926a939
 F test/sharedlock.test 5ede3c37439067c43b0198f580fd374ebf15d304
-F test/shell1.test f7a2ef8260aa01f20be3185118213b1ae70518fdcd2105f3e25b021b5ca800ac
+F test/shell1.test e4b4de56f454708e0747b52915135baa2cbfec4965406d6eaf02a4a5c22a9880
 F test/shell2.test 7a3a23a9f57b99453f1679b1fe8072cb30e382a622874c0c4d97695fadb0a787
-F test/shell3.test a50628ab1d78d90889d9d3f32fb2c084ee15674771e96afe954aaa0accd1de3c
-F test/shell4.test 8f6c0fce4abed19a8a7f7262517149812a04caa905d01bdc8f5e92573504b759
-F test/shell5.test 78a7a8516b1e7de560748881424f621321549023d3e5f7ed2e1c56497f64c06c
+F test/shell3.test 91febeac0412812bf6370abb8ed72700e32bf8f9878849414518f662dfd55e8a
+F test/shell4.test 7dc8a515705bc093d8ffe381670e8fa7a969661e8ed177c35c847e3c6dfc35e2
+F test/shell5.test c8b6c54f26ec537f8558273d7ed293ca3725ef42e6b12b8f151718628bd1473b
 F test/shell6.test 1ceb51b2678c472ba6cf1e5da96679ce8347889fe2c3bf93a0e0fa73f00b00d3
 F test/shell7.test 115132f66d0463417f408562cc2cf534f6bbc6d83a6d50f0072a9eb171bae97f
-F test/shell8.test 388471d16e4de767333107e30653983f186232c0e863f4490bb230419e830aae
+F test/shell8.test 3fd093d481aaa94dc77fb73f1044c1f19c7efe3477a395cc4f7450133bc54915
 F test/shmlock.test 3dbf017d34ab0c60abe6a44e447d3552154bd0c87b41eaf5ceacd408dd13fda5
 F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3
 F test/show_speedtest1_rtree.tcl 32e6c5f073d7426148a6936a0408f4b5b169aba5
@@ -1482,7 +1482,7 @@ F test/temptable.test d2c9b87a54147161bcd1822e30c1d1cd891e5b30
 F test/temptable2.test d2940417496e2b9548e01d09990763fbe88c316504033256d51493e1f1a5ce6a
 F test/temptable3.test d11a0974e52b347e45ee54ef1923c91ed91e4637
 F test/temptrigger.test 38f0ca479b1822d3117069e014daabcaacefffcc
-F test/tester.tcl 18448c7801d44cc5f2690f54f803da49ed994b3968f73a393cff329e55926679
+F test/tester.tcl eea76fe47703d4bd2d12ddc761fb0be623f9a7b878e50a2dcb7bd6fe4b3040f1
 F test/thread001.test b61a29dd87cf669f5f6ac96124a7c97d71b0c80d9012746072055877055cf9ef
 F test/thread002.test e630504f8a06c00bf8bbe68528774dd96aeb2e58
 F test/thread003.test ee4c9efc3b86a6a2767516a37bd64251272560a7
@@ -1953,8 +1953,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 4a4cecab23ef2aab20b1db466d045d56921590eb67563ab5a31f7b0a0f75c533
-R fa3a4ab48fbdc17706ad46278227efc1
+P f5f09368b33b6af00f96e5b8f763e7ee2d00ba6af2aee0f2ca86bb58c03d0b71
+R 84088aa54a74f88fa3741dd082a651c8
 U larrybr
-Z 88cf4bfe2e519f3edccdf0d39a577138
+Z 4cea09d549ba44b05dc5240e31984b9e
 # Remove this line to create a well-formed Fossil manifest.
index d9046afb0b88581351988c690505f533dab5bde5..b8969acb8f3758cf1e8d1c649dcb796ad539905d 100644 (file)
@@ -1 +1 @@
-f5f09368b33b6af00f96e5b8f763e7ee2d00ba6af2aee0f2ca86bb58c03d0b71
\ No newline at end of file
+0d3e2380197aa3e725591266acaeb0d43a7e794ca9153e6c56253cdcf60720b1
\ No newline at end of file
index 5e9bfa220a8733ceb199ddbb3a1d45e29d6a6354..1c22103f84531b37adfb808dc99fa006d4dd31d9 100644 (file)
@@ -8862,16 +8862,12 @@ static int do_meta_command(char *zLine, ShellState *p){
 
     failIfSafeMode(p, "cannot run .import in safe mode");
     memset(&sCtx, 0, sizeof(sCtx));
-    sCtx.z = sqlite3_malloc64(120);
-    if( sCtx.z==0 ){
-      import_cleanup(&sCtx);
-      shell_out_of_memory();
-    }
     if( p->mode==MODE_Ascii ){
       xRead = ascii_read_one_field;
     }else{
       xRead = csv_read_one_field;
     }
+    rc = 1;
     for(i=1; i<nArg; i++){
       char *z = azArg[i];
       if( z[0]=='-' && z[1]=='-' ) z++;
@@ -8883,7 +8879,7 @@ static int do_meta_command(char *zLine, ShellState *p){
         }else{
           utf8_printf(p->out, "ERROR: extra argument: \"%s\".  Usage:\n", z);
           showHelp(p->out, "import");
-          goto import_cleanup_fail;
+          goto meta_command_exit;
         }
       }else if( strcmp(z,"-v")==0 ){
         eVerbose++;
@@ -8904,16 +8900,13 @@ static int do_meta_command(char *zLine, ShellState *p){
       }else{
         utf8_printf(p->out, "ERROR: unknown option: \"%s\".  Usage:\n", z);
         showHelp(p->out, "import");
-        goto import_cleanup_fail;
+        goto meta_command_exit;
       }
     }
     if( zTable==0 ){
       utf8_printf(p->out, "ERROR: missing %s argument. Usage:\n",
                   zFile==0 ? "FILE" : "TABLE");
       showHelp(p->out, "import");
-    import_cleanup_fail:
-      rc = 1;
-      import_cleanup(&sCtx);
       goto meta_command_exit;
     }
     seenInterrupt = 0;
@@ -8925,20 +8918,19 @@ static int do_meta_command(char *zLine, ShellState *p){
       if( nSep==0 ){
         raw_printf(stderr,
                    "Error: non-null column separator required for import\n");
-        goto import_cleanup_fail;
+        goto meta_command_exit;
       }
       if( nSep>1 ){
-        raw_printf(stderr, 
+        raw_printf(stderr,
               "Error: multi-character column separators not allowed"
               " for import\n");
-        goto import_cleanup_fail;
+        goto meta_command_exit;
       }
       nSep = strlen30(p->rowSeparator);
       if( nSep==0 ){
         raw_printf(stderr,
             "Error: non-null row separator required for import\n");
-        rc = 1;
-        goto import_cleanup_fail;
+        goto meta_command_exit;
       }
       if( nSep==2 && p->mode==MODE_Csv && strcmp(p->rowSeparator,SEP_CrLf)==0 ){
         /* When importing CSV (only), if the row separator is set to the
@@ -8951,7 +8943,7 @@ static int do_meta_command(char *zLine, ShellState *p){
       if( nSep>1 ){
         raw_printf(stderr, "Error: multi-character row separators not allowed"
                            " for import\n");
-        goto import_cleanup_fail;
+        goto meta_command_exit;
       }
       sCtx.cColSep = p->colSeparator[0];
       sCtx.cRowSep = p->rowSeparator[0];
@@ -8961,7 +8953,7 @@ static int do_meta_command(char *zLine, ShellState *p){
     if( sCtx.zFile[0]=='|' ){
 #ifdef SQLITE_OMIT_POPEN
       raw_printf(stderr, "Error: pipes are not supported in this OS\n");
-      goto import_cleanup_fail;
+      goto meta_command_exit;
 #else
       sCtx.in = popen(sCtx.zFile+1, "r");
       sCtx.zFile = "<pipe>";
@@ -8973,8 +8965,9 @@ static int do_meta_command(char *zLine, ShellState *p){
     }
     if( sCtx.in==0 ){
       utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
-      goto import_cleanup_fail;
+      goto meta_command_exit;
     }
+    rc = 0;
     if( eVerbose>=2 || (eVerbose>=1 && useOutputMode) ){
       char zSep[2];
       zSep[1] = 0;
@@ -8986,6 +8979,11 @@ static int do_meta_command(char *zLine, ShellState *p){
       output_c_string(p->out, zSep);
       utf8_printf(p->out, "\n");
     }
+    sCtx.z = sqlite3_malloc64(120);
+    if( sCtx.z==0 ){
+      import_cleanup(&sCtx);
+      shell_out_of_memory();
+    }
     /* Below, resources must be freed before exit. */
     while( (nSkip--)>0 ){
       while( xRead(&sCtx) && sCtx.cTerm==sCtx.cColSep ){}
index 3c7061c55d1a17db9f60d4e034521cd5a9a87dd7..26426535b7e2ce085bbf77455e23e147ea5a20f2 100644 (file)
@@ -23,7 +23,7 @@
 #
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
-set CLI [test_find_cli]
+set CLI [test_cli_invocation]
 db close
 forcedelete test.db test.db-journal test.db-wal
 sqlite3 db test.db
index e5a0c124e0d4af134cc57097fef0e524a95e4ba9..f8d69946e7cbdbdd5586acf0911df9d1e6bb759f 100644 (file)
@@ -22,7 +22,7 @@
 #
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
-set CLI [test_find_cli]
+set CLI [test_cli_invocation]
 db close
 forcedelete test.db test.db-journal test.db-wal
 sqlite3 db test.db
index ee7d2b856f28322cc7623b3a4b854b1954ae8031..068072202dc1e1665b85bbb8402821eb3e2665a1 100644 (file)
@@ -23,7 +23,8 @@
 #
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
-set CLI [test_find_cli]
+set CLI [test_cli_invocation]
+set CLI_ONLY [test_find_cli]
 db close
 forcedelete test.db test.db-journal test.db-wal
 sqlite3 db test.db
@@ -130,13 +131,13 @@ do_test shell4-3.1 {
   set fd [open t1.txt wb]
   puts $fd "SELECT 'squirrel';"
   close $fd
-  exec $::CLI :memory: --interactive ".read t1.txt"
+  exec $::CLI_ONLY :memory: --interactive ".read t1.txt"
 } {squirrel}
 do_test shell4-3.2 {
   set fd [open t1.txt wb]
   puts $fd "SELECT 'pound: \302\243';"
   close $fd
-  exec $::CLI :memory: --interactive ".read t1.txt"
+  exec $::CLI_ONLY :memory: --interactive ".read t1.txt"
 } {pound: £}
 
 do_test shell4-4.1 {
index 00d89f8d78c20e68111306638ec2c7eedb49915f..39018a0ce9bc7f38324848ad6cf690f16d540b52 100644 (file)
@@ -21,7 +21,7 @@
 #
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
-set CLI [test_find_cli]
+set CLI [test_cli_invocation]
 db close
 forcedelete test.db test.db-journal test.db-wal
 
index ddb4a47b82dcd40f4deafc00092f25039d23762f..bee603923201221911b900e3614dc6c9c0548f91 100644 (file)
@@ -19,7 +19,7 @@ set testprefix shell8
 ifcapable !vtab {
   finish_test; return
 }
-set CLI [test_find_cli]
+set CLI [test_cli_invocation]
 
 # Check to make sure the shell has been compiled with ".archive" support.
 #
index 9d29fdb8df00c19604aef35eb9db39838800b00d..4dee3b5a8b8ca71b861371c734bfe08c6867d435 100644 (file)
@@ -2478,7 +2478,7 @@ proc test_find_binary {nm} {
 }
 
 # Find the name of the 'shell' executable (e.g. "sqlite3.exe") to use for
-# the tests in shell[1-5].test. If no such executable can be found, invoke
+# the tests in shell*.test. If no such executable can be found, invoke
 # [finish_test ; return] in the callers context.
 #
 proc test_find_cli {} {
@@ -2487,6 +2487,32 @@ proc test_find_cli {} {
   return $prog
 }
 
+# Find invocation of the 'shell' executable (e.g. "sqlite3.exe") to use
+# for the tests in shell*.test with optional valgrind prefix when the
+# environment variable SQLITE_CLI_VALGRIND_OPT is set. The set value
+# operates as follows:
+#   empty or 0 => no valgrind prefix;
+#   1 => valgrind options for memory leak check;
+#   other => use value as valgrind options.
+# If shell not found, invoke [finish_test ; return] in callers context.
+#
+proc test_cli_invocation {} {
+  set prog [test_find_binary sqlite3]
+  if {$prog==""} { return -code return }
+  if {[info exists ::env(SQLITE_CLI_VALGRIND_OPT)]} {
+    set vgo $::env(SQLITE_CLI_VALGRIND_OPT)
+    if {$vgo == 0 || $vgo eq ""} {
+      return $prog
+    } elseif {$vgo == 1} {
+      return "valgrind -q --leak-check=yes $prog"
+    } else {
+      return "valgrind $vgo $prog"
+    }
+  } else {
+    return $prog
+  }
+}
+
 # Find the name of the 'sqldiff' executable (e.g. "sqlite3.exe") to use for
 # the tests in sqldiff tests. If no such executable can be found, invoke
 # [finish_test ; return] in the callers context.