Bug 1071360 - Fix async storage connection closing when open fails, r=asuth.

This commit is contained in:
Ben Turner 2015-03-27 22:45:28 -07:00
Родитель b4996c2b7c
Коммит 056431018e
3 изменённых файлов: 23 добавлений и 4 удалений

Просмотреть файл

@ -10,6 +10,8 @@
# another mozconfig file, you'll need to use mozconfig.common.override instead
# of this file.
MOZ_CRASHREPORTER_UPLOAD_FULL_SYMBOLS=1
mk_add_options AUTOCLOBBER=1
ac_add_options --enable-crashreporter

Просмотреть файл

@ -872,7 +872,8 @@ nsresult
Connection::internalClose(sqlite3 *aNativeConnection)
{
// Sanity checks to make sure we are in the proper state before calling this.
MOZ_ASSERT(aNativeConnection, "Database connection is invalid!");
// aNativeConnection can be null if OpenAsyncDatabase failed and is now just
// cleaning up the async thread.
MOZ_ASSERT(!isClosed());
#ifdef DEBUG
@ -901,6 +902,11 @@ Connection::internalClose(sqlite3 *aNativeConnection)
MutexAutoLock lockedScope(sharedAsyncExecutionMutex);
mConnectionClosed = true;
}
// Nothing else needs to be done if we don't have a connection here.
if (!aNativeConnection)
return NS_OK;
int srv = sqlite3_close(aNativeConnection);
if (srv == SQLITE_BUSY) {
@ -1148,11 +1154,14 @@ Connection::AsyncClose(mozIStorageCompletionCallback *aCallback)
if (!NS_IsMainThread()) {
return NS_ERROR_NOT_SAME_THREAD;
}
if (!mDBConn)
return NS_ERROR_NOT_INITIALIZED;
// It's possible to get here with a null mDBConn but a non-null async
// execution target if OpenAsyncDatabase failed somehow, so don't exit early
// in that case.
nsIEventTarget *asyncThread = getAsyncExecutionTarget();
NS_ENSURE_TRUE(asyncThread, NS_ERROR_NOT_INITIALIZED);
if (!mDBConn && !asyncThread)
return NS_ERROR_NOT_INITIALIZED;
// setClosedState nullifies our connection pointer, so we take a raw pointer
// off it, to pass it through the close procedure.

Просмотреть файл

@ -684,6 +684,14 @@ public:
nsresult rv = mStorageFile ? mConnection->initialize(mStorageFile)
: mConnection->initialize();
if (NS_FAILED(rv)) {
nsCOMPtr<nsIRunnable> closeRunnable =
NS_NewRunnableMethodWithArg<mozIStorageCompletionCallback*>(
mConnection.get(),
&Connection::AsyncClose,
nullptr);
MOZ_ASSERT(closeRunnable);
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToMainThread(closeRunnable)));
return DispatchResult(rv, nullptr);
}