mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1071360 - Fix async storage connection closing when open fails, r=asuth.
This commit is contained in:
parent
da6b685df9
commit
d9586ec6d6
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user