1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-14 00:22:38 +03:00

Add tests to check that sqlite recovers from an error in sqlite3_initialize() correctly.

FossilOrigin-Name: 904a371c6c9d3f20332b37767b06161fa0a78113
This commit is contained in:
dan
2009-08-17 15:16:19 +00:00
parent 9ac06509f1
commit e1ab219309
11 changed files with 414 additions and 42 deletions

View File

@@ -124,6 +124,7 @@ int sqlite3_initialize(void){
*/
pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
sqlite3_mutex_enter(pMaster);
sqlite3GlobalConfig.isMutexInit = 1;
if( !sqlite3GlobalConfig.isMallocInit ){
rc = sqlite3MallocInit();
}
@@ -142,10 +143,9 @@ int sqlite3_initialize(void){
}
sqlite3_mutex_leave(pMaster);
/* If unable to initialize the malloc subsystem, then return early.
** There is little hope of getting SQLite to run if the malloc
** subsystem cannot be initialized.
*/
/* If rc is not SQLITE_OK at this point, then either the malloc
** subsystem could not be initialized or the system failed to allocate
** the pInitMutex mutex. Return an error in either case. */
if( rc!=SQLITE_OK ){
return rc;
}
@@ -162,8 +162,11 @@ int sqlite3_initialize(void){
sqlite3GlobalConfig.inProgress = 1;
memset(pHash, 0, sizeof(sqlite3GlobalFunctions));
sqlite3RegisterGlobalFunctions();
rc = sqlite3PcacheInitialize();
if( sqlite3GlobalConfig.isPCacheInit==0 ){
rc = sqlite3PcacheInitialize();
}
if( rc==SQLITE_OK ){
sqlite3GlobalConfig.isPCacheInit = 1;
rc = sqlite3_os_init();
}
if( rc==SQLITE_OK ){
@@ -219,14 +222,23 @@ int sqlite3_initialize(void){
*/
int sqlite3_shutdown(void){
if( sqlite3GlobalConfig.isInit ){
sqlite3GlobalConfig.isMallocInit = 0;
sqlite3PcacheShutdown();
sqlite3_os_end();
sqlite3_reset_auto_extension();
sqlite3MallocEnd();
sqlite3MutexEnd();
sqlite3GlobalConfig.isInit = 0;
}
if( sqlite3GlobalConfig.isPCacheInit ){
sqlite3PcacheShutdown();
sqlite3GlobalConfig.isPCacheInit = 0;
}
if( sqlite3GlobalConfig.isMallocInit ){
sqlite3MallocEnd();
sqlite3GlobalConfig.isMallocInit = 0;
}
if( sqlite3GlobalConfig.isMutexInit ){
sqlite3MutexEnd();
sqlite3GlobalConfig.isMutexInit = 0;
}
return SQLITE_OK;
}