Skip to content

Commit

Permalink
Bug 915214 - Fix possible crash when shutting down the database conne…
Browse files Browse the repository at this point in the history
…ction in mozStorageConnection.cpp. r=Yoric
  • Loading branch information
Paolo Amadini committed Oct 24, 2013
1 parent d14eb09 commit 39efd6c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions storage/src/mozStorageConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,20 +824,25 @@ Connection::internalClose()
leafName.get()));
#endif

// Set the property to null before closing the connection, otherwise the other
// functions in the module may try to use the connection after it is closed.
sqlite3 *dbConn = mDBConn;
mDBConn = nullptr;

// At this stage, we may still have statements that need to be
// finalized. Attempt to close the database connection. This will
// always disconnect any virtual tables and cleanly finalize their
// internal statements. Once this is done, closing may fail due to
// unfinalized client statements, in which case we need to finalize
// these statements and close again.

int srv = sqlite3_close(mDBConn);
int srv = sqlite3_close(dbConn);

if (srv == SQLITE_BUSY) {
// We still have non-finalized statements. Finalize them.

sqlite3_stmt *stmt = nullptr;
while ((stmt = ::sqlite3_next_stmt(mDBConn, stmt))) {
while ((stmt = ::sqlite3_next_stmt(dbConn, stmt))) {
PR_LOG(gStorageLog, PR_LOG_NOTICE,
("Auto-finalizing SQL statement '%s' (%x)",
::sqlite3_sql(stmt),
Expand Down Expand Up @@ -871,8 +876,8 @@ Connection::internalClose()
}

// Now that all statements have been finalized, we
// shoudl be able to close.
srv = ::sqlite3_close(mDBConn);
// should be able to close.
srv = ::sqlite3_close(dbConn);

}

Expand All @@ -881,7 +886,6 @@ Connection::internalClose()
"sqlite3_close failed. There are probably outstanding statements that are listed above!");
}

mDBConn = nullptr;
return convertResultCode(srv);
}

Expand Down

0 comments on commit 39efd6c

Please sign in to comment.