Hi I noticed a memory leak when using the .dump command of command line tool "sqlite3". I initially saw it when using spatialite but the same bug exists in latest sqlite-3.7.0.1. A block of memory is leaked each time the ".dump" command is used.
In the following example, I run .dump 3 times and valgrind finds 3 blocks of memory leaked: $ valgrind --trace-children=yes --leak-check=yes \ --track-fds=yes ./sqlite3 2> vg.log SQLite version 3.7.0.1 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> CREATE TABLE t (a INT); sqlite> .dump PRAGMA foreign_keys=OFF; BEGIN TRANSACTION; CREATE TABLE t (a INT); COMMIT; sqlite> .dump PRAGMA foreign_keys=OFF; BEGIN TRANSACTION; CREATE TABLE t (a INT); COMMIT; sqlite> .dump PRAGMA foreign_keys=OFF; BEGIN TRANSACTION; CREATE TABLE t (a INT); COMMIT; sqlite> .quit And file vg.log contains: ==5015== 12 bytes in 3 blocks are definitely lost in loss record 10 of 52 ==5015== at 0x4024F70: malloc (vg_replace_malloc.c:236) ==5015== by 0x4024FFA: realloc (vg_replace_malloc.c:525) ==5015== by 0x804997A: appendText (shell.c:895) ==5015== by 0x8049F83: dump_callback (shell.c:1148) ==5015== by 0x4094027: sqlite3_exec (sqlite3.c:82322) ==5015== by 0x804AA14: T.339 (shell.c:1197) ==5015== by 0x804E3EB: do_meta_command (shell.c:1460) ==5015== by 0x804BC35: process_input (shell.c:2195) ==5015== by 0x804EED8: main (shell.c:2615) Following patch fixes it: $ diff -c shell.c.ORIG shell.c *** shell.c.ORIG 2010-08-07 11:38:07.715422705 +0200 --- shell.c 2010-08-07 11:38:13.555496088 +0200 *************** *** 1148,1153 **** --- 1148,1154 ---- zTmp = appendText(zTmp, zTable, '"'); if( zTmp ){ zSelect = appendText(zSelect, zTmp, '\''); + free(zTmp); } zSelect = appendText(zSelect, " || ' VALUES(' || ", 0); rc = sqlite3_step(pTableInfo); Regards -- Dominique _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users