Make sure the mutex is held while calling sqlite3ApiExit() in 
sqlite3_wal_checkpoint().  Other cleanup of WAL logic.

FossilOrigin-Name: 11a85b821abff1ecb7ec8c37bc7783be9fc4ea6d
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index c216816..842917a 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -824,7 +824,6 @@
   void *pUpdateArg;
   void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64);
 #ifndef SQLITE_OMIT_WAL
-  int nAutoCheckpoint;          /* Value configured by wal_autocheckpoint() */
   int (*xWalCallback)(void *, sqlite3 *, const char *, int);
   void *pWalArg;
 #endif
@@ -3000,6 +2999,7 @@
 VTable *sqlite3GetVTable(sqlite3*, Table*);
 const char *sqlite3JournalModename(int);
 int sqlite3Checkpoint(sqlite3*, int);
+int sqlite3WalDefaultHook(void*,sqlite3*,const char*,int);
 
 /* Declarations for functions in fkey.c. All of these are replaced by
 ** no-op macros if OMIT_FOREIGN_KEY is defined. In this case no foreign