Bug 728653 - Crash in mozilla::storage::Connection::stepStatement @ sqlite3_extended_result_codes. r=mak.
authorRafael Ávila de Espíndola <respindola@mozilla.com>
Thu, 01 Mar 2012 08:13:45 -0500
changeset 88284 b92e7499019ef5d97fd483ca84d45d7e6d2485a0
parent 88283 f50254fe891267904b58c4a38e95ad765fafc78c
child 88285 91ca0cc06f46dc519ee50403131b7f8fd3e4089d
push id157
push userMs2ger@gmail.com
push dateWed, 07 Mar 2012 19:27:10 +0000
reviewersmak
bugs728653
milestone13.0a1
Bug 728653 - Crash in mozilla::storage::Connection::stepStatement @ sqlite3_extended_result_codes. r=mak.
storage/src/mozStorageConnection.cpp
--- a/storage/src/mozStorageConnection.cpp
+++ b/storage/src/mozStorageConnection.cpp
@@ -872,16 +872,26 @@ Connection::getFilename()
 }
 
 int
 Connection::stepStatement(sqlite3_stmt *aStatement)
 {
   bool checkedMainThread = false;
   TimeStamp startTime = TimeStamp::Now();
 
+  // mDBConn may be null if the executing statement has been created and cached
+  // after a call to asyncClose() but before the connection has been nullified
+  // by internalClose().  In such a case closing the connection fails due to
+  // the existence of prepared statements, but mDBConn is set to null
+  // regardless. This usually happens when other tasks using cached statements
+  // are asynchronously scheduled for execution and any of them ends up after
+  // asyncClose. See bug 728653 for details.
+  if (!mDBConn)
+    return SQLITE_MISUSE;
+
   (void)::sqlite3_extended_result_codes(mDBConn, 1);
 
   int srv;
   while ((srv = ::sqlite3_step(aStatement)) == SQLITE_LOCKED_SHAREDCACHE) {
     if (!checkedMainThread) {
       checkedMainThread = true;
       if (::NS_IsMainThread()) {
         NS_WARNING("We won't allow blocking on the main thread!");