]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Stop a memory leak in .import, and add leak complaint to CLI debug builds.
authorlarrybr <larrybr@noemail.net>
Sat, 7 May 2022 03:53:14 +0000 (03:53 +0000)
committerlarrybr <larrybr@noemail.net>
Sat, 7 May 2022 03:53:14 +0000 (03:53 +0000)
FossilOrigin-Name: f5f09368b33b6af00f96e5b8f763e7ee2d00ba6af2aee0f2ca86bb58c03d0b71

manifest
manifest.uuid
src/shell.c.in

index 0a9a9820e133986453e8745b2eb39177da79bea0..7ac50b6a3c1d012e45d81e01060f832bd5777b89 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Create\snew\sbranch\snamed\s"import-leak-plug"
-D 2022-05-07T02:21:17.769
+C Stop\sa\smemory\sleak\sin\s.import,\sand\sadd\sleak\scomplaint\sto\sCLI\sdebug\sbuilds.
+D 2022-05-07T03:53:14.691
 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 ae0a6fae983caac6f8c824733f0599dfdf7b3a7e8efdef3cb5e3ab2e457ffc35
+F src/shell.c.in 6b7ddce6ebfb52633236c174928f84558fa7471eed99ce189014d40df990c97b
 F src/sqlite.h.in 2a35f62185eb5e7ecc64a2f68442b538ce9be74f80f28a00abc24837edcf1c17
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
 F src/sqlite3ext.h f49e28c25bd941e79794db5415fdf7b202deb3bc072ed6f1ed273d578703684e
@@ -1953,11 +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 dac6d87c71606f3ec7ce601be6d17357d323476ecb60dbb167030146783b62b2
-R fb5b71dd78e91f00920386e6c95ee22a
-T *branch * import-leak-plug
-T *sym-import-leak-plug *
-T -sym-trunk *
+P 4a4cecab23ef2aab20b1db466d045d56921590eb67563ab5a31f7b0a0f75c533
+R fa3a4ab48fbdc17706ad46278227efc1
 U larrybr
-Z 513f56eca52f57dd200e788d0d348907
+Z 88cf4bfe2e519f3edccdf0d39a577138
 # Remove this line to create a well-formed Fossil manifest.
index f893f4fe4c982b76fe691bfa800e045f8a9ee6f8..d9046afb0b88581351988c690505f533dab5bde5 100644 (file)
@@ -1 +1 @@
-4a4cecab23ef2aab20b1db466d045d56921590eb67563ab5a31f7b0a0f75c533
\ No newline at end of file
+f5f09368b33b6af00f96e5b8f763e7ee2d00ba6af2aee0f2ca86bb58c03d0b71
\ No newline at end of file
index 95a32f524717d1346a101ffd7bc3eb34aa2928bd..5e9bfa220a8733ceb199ddbb3a1d45e29d6a6354 100644 (file)
@@ -8883,8 +8883,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");
-          rc = 1;
-          goto meta_command_exit;
+          goto import_cleanup_fail;
         }
       }else if( strcmp(z,"-v")==0 ){
         eVerbose++;
@@ -8905,15 +8904,16 @@ 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");
-        rc = 1;
-        goto meta_command_exit;
+        goto import_cleanup_fail;
       }
     }
     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,22 +8925,20 @@ static int do_meta_command(char *zLine, ShellState *p){
       if( nSep==0 ){
         raw_printf(stderr,
                    "Error: non-null column separator required for import\n");
-        rc = 1;
-        goto meta_command_exit;
+        goto import_cleanup_fail;
       }
       if( nSep>1 ){
         raw_printf(stderr, 
               "Error: multi-character column separators not allowed"
               " for import\n");
-        rc = 1;
-        goto meta_command_exit;
+        goto import_cleanup_fail;
       }
       nSep = strlen30(p->rowSeparator);
       if( nSep==0 ){
         raw_printf(stderr,
             "Error: non-null row separator required for import\n");
         rc = 1;
-        goto meta_command_exit;
+        goto import_cleanup_fail;
       }
       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
@@ -8953,8 +8951,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");
-        rc = 1;
-        goto meta_command_exit;
+        goto import_cleanup_fail;
       }
       sCtx.cColSep = p->colSeparator[0];
       sCtx.cRowSep = p->rowSeparator[0];
@@ -8964,8 +8961,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");
-      rc = 1;
-      goto meta_command_exit;
+      goto import_cleanup_fail;
 #else
       sCtx.in = popen(sCtx.zFile+1, "r");
       sCtx.zFile = "<pipe>";
@@ -8977,9 +8973,7 @@ static int do_meta_command(char *zLine, ShellState *p){
     }
     if( sCtx.in==0 ){
       utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
-      rc = 1;
-      import_cleanup(&sCtx);
-      goto meta_command_exit;
+      goto import_cleanup_fail;
     }
     if( eVerbose>=2 || (eVerbose>=1 && useOutputMode) ){
       char zSep[2];
@@ -11863,6 +11857,9 @@ int SQLITE_CDECL main(int argc, char **argv){
 #else
 int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
   char **argv;
+#endif
+#ifdef SQLITE_DEBUG
+  sqlite3_uint64 mem_main_enter = sqlite3_memory_used();
 #endif
   char *zErrMsg = 0;
   ShellState data;
@@ -12430,5 +12427,11 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
   /* Clear the global data structure so that valgrind will detect memory
   ** leaks */
   memset(&data, 0, sizeof(data));
+#ifdef SQLITE_DEBUG
+  if( sqlite3_memory_used()>mem_main_enter ){
+    utf8_printf(stderr, "Memory leaked: %u bytes\n",
+                (unsigned int)(sqlite3_memory_used()-mem_main_enter));
+  }
+#endif
   return rc;
 }