From: drh Date: Fri, 16 Sep 2016 19:11:03 +0000 (+0000) Subject: Fix problems with the fileRead() function in the command-line shell. Fix X-Git-Tag: version-3.15.0~83 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d145915a598a5c410b6288070904d4b00b1961e5;p=thirdparty%2Fsqlite.git Fix problems with the fileRead() function in the command-line shell. Fix a harmless memory leak in the command-line shell, to make validation testing easier. FossilOrigin-Name: e660402e5e654b7f37ad2ce201df5cbb2b9eb9a6 --- diff --git a/manifest b/manifest index 7e4f14716b..ba74c6d21a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sthe\s#ifdef\sSQLITE_DEBUG\sfrom\saround\sthe\stestcase_glob()\sroutine\nin\sthe\scommand-line\sshell. -D 2016-09-16T18:53:42.407 +C Fix\sproblems\swith\sthe\sfileRead()\sfunction\sin\sthe\scommand-line\sshell.\s\sFix\na\sharmless\smemory\sleak\sin\sthe\scommand-line\sshell,\sto\smake\svalidation\stesting\neasier. +D 2016-09-16T19:11:03.888 F Makefile.in 6fd48ffcf7c2deea7499062d1f3747f986c19678 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e1aa788e84f926e42239ee167c53f785bedacacd @@ -387,7 +387,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 3c3cf0dc719cd2a32ab5c1e10c26481dd565492e F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c 244f9cc5e4662987cd2ef5c22d1b7027560f3425 -F src/shell.c 6fbbb69f5377550b9c00932077c09fde86dad0f7 +F src/shell.c 131978e994157b3925efd6fdf0e0c4ed9ab2cf91 F src/sqlite.h.in 46ed821aeed0ba45559fb15597d9a400083154a2 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae @@ -1525,7 +1525,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P a92aee5520cfaf85ae896365a7e42bdd981f828d -R ee0cf31a4951ba6f76f2503b1e8b6ac4 +P 9885dac4b98693c4d2ed643022127f1452f19dc6 +R 88f539d71fa2571070b5d308155e3cfc U drh -Z 869e33134584b23a4d21c5bff81dceaf +Z 09ffb02e347dfbb4f5f38eddcacdd3ba diff --git a/manifest.uuid b/manifest.uuid index 21cf26c1c4..ac0e0ae411 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9885dac4b98693c4d2ed643022127f1452f19dc6 \ No newline at end of file +e660402e5e654b7f37ad2ce201df5cbb2b9eb9a6 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index cd148e6de3..1dad6d9c2a 100644 --- a/src/shell.c +++ b/src/shell.c @@ -2252,17 +2252,21 @@ static int process_input(ShellState *p, FILE *in); static char *readFile(const char *zName){ FILE *in = fopen(zName, "rb"); long nIn; + size_t nRead; char *pBuf; if( in==0 ) return 0; fseek(in, 0, SEEK_END); nIn = ftell(in); rewind(in); - pBuf = sqlite3_malloc64( nIn ); + pBuf = sqlite3_malloc64( nIn+1 ); if( pBuf==0 ) return 0; - if( 1!=fread(pBuf, nIn, 1, in) ){ + nRead = fread(pBuf, nIn, 1, in); + fclose(in); + if( nRead!=1 ){ sqlite3_free(pBuf); return 0; } + pBuf[nIn] = 0; return pBuf; } @@ -5203,8 +5207,13 @@ static int process_input(ShellState *p, FILE *in){ ** Return a pathname which is the user's home directory. A ** 0 return indicates an error of some kind. */ -static char *find_home_dir(void){ +static char *find_home_dir(int clearFlag){ static char *home_dir = NULL; + if( clearFlag ){ + free(home_dir); + home_dir = 0; + return 0; + } if( home_dir ) return home_dir; #if !defined(_WIN32) && !defined(WIN32) && !defined(_WIN32_WCE) \ @@ -5279,7 +5288,7 @@ static void process_sqliterc( FILE *in = NULL; if (sqliterc == NULL) { - home_dir = find_home_dir(); + home_dir = find_home_dir(0); if( home_dir==0 ){ raw_printf(stderr, "-- warning: cannot find home directory;" " cannot read ~/.sqliterc\n"); @@ -5767,7 +5776,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ printf(".\nUse \".open FILENAME\" to reopen on a " "persistent database.\n"); } - zHome = find_home_dir(); + zHome = find_home_dir(0); if( zHome ){ nHistory = strlen30(zHome) + 20; if( (zHistory = malloc(nHistory))!=0 ){ @@ -5791,6 +5800,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ sqlite3_close(data.db); } sqlite3_free(data.zFreeOnClose); + find_home_dir(1); #if !SQLITE_SHELL_IS_UTF8 for(i=0; i