From 0a5490715925605759dfa60991f974bcc184d1be Mon Sep 17 00:00:00 2001 From: danielk1977 Date: Tue, 17 Feb 2009 16:29:10 +0000 Subject: [PATCH] Allow sqlite3_shutdown() to be called by a process before sqlite3_initialize() is. Prior to this commit such a call could segfault. (CVS 6296) FossilOrigin-Name: 79431c58d964d6057c7f42f7c1df74f3df4493eb --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/malloc.c | 6 ++++-- src/mutex.c | 6 ++++-- src/tclsqlite.c | 8 +++++++- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index 9c303eb482..03eed1157b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\ssure\sresult\svariables\sare\sinitialized\sor\sunused\sfollowing\sa\sfailure\nof\sthe\sxFullPathname\sVFS\sinterface.\s\sProblem\sdetected\sby\svalgrind.\s(CVS\s6295) -D 2009-02-17T16:17:02 +C Allow\ssqlite3_shutdown()\sto\sbe\scalled\sby\sa\sprocess\sbefore\ssqlite3_initialize()\sis.\sPrior\sto\sthis\scommit\ssuch\sa\scall\scould\ssegfault.\s(CVS\s6296) +D 2009-02-17T16:29:11 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in c7a5a30fb6852bd7839b1024e1661da8549878ee F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -124,14 +124,14 @@ F src/journal.c e00df0c0da8413ab6e1bb7d7cab5665d4a9000d0 F src/legacy.c 8b3b95d48d202614946d7ce7256e7ba898905c3b F src/loadext.c 3f96631089fc4f3871a67f02f2e4fc7ea4d51edc F src/main.c 4912460dab29e4d37e4ba1d78320c6a77bb95ad8 -F src/malloc.c bc408056b126db37b6fba00e170d578cc67be6b3 +F src/malloc.c 836bc7ead9b255a61d56d5589b24e1dad6704604 F src/mem0.c f2f84062d1f35814d6535c9f9e33de3bfb3b132c F src/mem1.c 3bfb39e4f60b0179713a7c087b2d4f0dc205735f F src/mem2.c 6f46eef2c2cce452ae38f5b98c2632712e858bc9 F src/mem3.c 67153ec933e08b70714055e872efb58a6b287939 F src/mem5.c 838309b521c96a2a34507f74a5a739d28de4aac6 F src/memjournal.c 17e9281ea5d7981e3e7b0dd3274921ecba4f773c -F src/mutex.c e9cb5fbe94afb4328869afaf3ac49bd1327559eb +F src/mutex.c 5e2ea0e0490a3567dc08a014bcee748c0cea727f F src/mutex.h 9e686e83a88838dac8b9c51271c651e833060f1e F src/mutex_noop.c f5a07671f25a1a9bd7c10ad7107bc2585446200f F src/mutex_os2.c 6b5a74f812082a8483c3df05b47bbaac2424b9a0 @@ -163,7 +163,7 @@ F src/sqliteInt.h 55cc7e45a7fcc166be62b984168dd69159d877eb F src/sqliteLimit.h ffe93f5a0c4e7bd13e70cd7bf84cfb5c3465f45d F src/status.c 237b193efae0cf6ac3f0817a208de6c6c6ef6d76 F src/table.c 332ab0ea691e63862e2a8bdfe2c0617ee61062a3 -F src/tclsqlite.c 524c1f49ccf9b6a5e3917591cf3b6c4f4204e607 +F src/tclsqlite.c c18d6b71b3a01ded68e4479b128116e67eecfd2c F src/test1.c f88b447699786d58a0136a3a48b12990abc72c8a F src/test2.c 71c22e2974f8094fe0fd1eba8f27872dde9b2a39 F src/test3.c 88a246b56b824275300e6c899634fbac1dc94b14 @@ -701,7 +701,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P 68f15442e8db364952d30daf4ce60c6b938f5906 -R d1aad110f68975c95dc4ed818ce8aeba -U drh -Z 4902f559ade9ef6adea70c902c58230a +P 59a4755185f0e51699cd020ae67d279bee45de1c +R c00d45d1c8c16889bdb28d67afb51798 +U danielk1977 +Z 4e995aca588943513f3969ac24dc04b4 diff --git a/manifest.uuid b/manifest.uuid index e4cf04a6df..04d5824395 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -59a4755185f0e51699cd020ae67d279bee45de1c \ No newline at end of file +79431c58d964d6057c7f42f7c1df74f3df4493eb \ No newline at end of file diff --git a/src/malloc.c b/src/malloc.c index a92fae06b6..d9c036da66 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -12,7 +12,7 @@ ** ** Memory allocation functions used throughout sqlite. ** -** $Id: malloc.c,v 1.54 2009/01/20 16:53:41 danielk1977 Exp $ +** $Id: malloc.c,v 1.55 2009/02/17 16:29:11 danielk1977 Exp $ */ #include "sqliteInt.h" #include @@ -153,7 +153,9 @@ int sqlite3MallocInit(void){ ** Deinitialize the memory allocation subsystem. */ void sqlite3MallocEnd(void){ - sqlite3GlobalConfig.m.xShutdown(sqlite3GlobalConfig.m.pAppData); + if( sqlite3GlobalConfig.m.xShutdown ){ + sqlite3GlobalConfig.m.xShutdown(sqlite3GlobalConfig.m.pAppData); + } memset(&mem0, 0, sizeof(mem0)); } diff --git a/src/mutex.c b/src/mutex.c index 03cae57bf9..d7b769d730 100644 --- a/src/mutex.c +++ b/src/mutex.c @@ -14,7 +14,7 @@ ** This file contains code that is common across all mutex implementations. ** -** $Id: mutex.c,v 1.29 2008/10/07 15:25:48 drh Exp $ +** $Id: mutex.c,v 1.30 2009/02/17 16:29:11 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -67,7 +67,9 @@ int sqlite3MutexInit(void){ */ int sqlite3MutexEnd(void){ int rc = SQLITE_OK; - rc = sqlite3GlobalConfig.mutex.xMutexEnd(); + if( sqlite3GlobalConfig.mutex.xMutexEnd ){ + rc = sqlite3GlobalConfig.mutex.xMutexEnd(); + } return rc; } diff --git a/src/tclsqlite.c b/src/tclsqlite.c index 4e7f77dd2e..585360f568 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -12,7 +12,7 @@ ** A TCL Interface to SQLite. Append this file to sqlite3.c and ** compile the whole thing to build a TCL-enabled version of SQLite. ** -** $Id: tclsqlite.c,v 1.236 2009/02/04 22:46:47 drh Exp $ +** $Id: tclsqlite.c,v 1.237 2009/02/17 16:29:11 danielk1977 Exp $ */ #include "tcl.h" #include @@ -2744,6 +2744,12 @@ static char zMainloop[] = #define TCLSH_MAIN main /* Needed to fake out mktclapp */ int TCLSH_MAIN(int argc, char **argv){ Tcl_Interp *interp; + + /* Call sqlite3_shutdown() once before doing anything else. This is to + ** test that sqlite3_shutdown() can be safely called by a process before + ** sqlite3_initialize() is. */ + sqlite3_shutdown(); + Tcl_FindExecutable(argv[0]); interp = Tcl_CreateInterp(); Sqlite3_Init(interp); -- 2.47.2