Bug 1558112 - LSNG: Connection::FlushOp::DoDatastoreWork needs to automatically detach the shadow database on an error; r=asuth

Differential Revision: https://phabricator.services.mozilla.com/D34311
This commit is contained in:
Jan Varga 2019-06-10 08:41:13 +02:00
Родитель 88e7ba6db9
Коммит 5346f3347e
1 изменённых файлов: 36 добавлений и 0 удалений

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

@ -4497,6 +4497,34 @@ nsresult Connection::FlushOp::DoDatastoreWork() {
AssertIsOnConnectionThread();
MOZ_ASSERT(mConnection);
class MOZ_STACK_CLASS AutoDetach final {
nsCOMPtr<mozIStorageConnection> mConnection;
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
public:
explicit AutoDetach(
mozIStorageConnection* aConnection MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
: mConnection(aConnection) {
MOZ_ASSERT(aConnection);
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
}
~AutoDetach() {
if (mConnection) {
nsresult rv = DetachShadowDatabase(mConnection);
Unused << NS_WARN_IF(NS_FAILED(rv));
}
}
void release() { mConnection = nullptr; }
private:
explicit AutoDetach(const AutoDetach&) = delete;
AutoDetach& operator=(const AutoDetach&) = delete;
AutoDetach& operator=(AutoDetach&&) = delete;
};
QuotaManager* quotaManager = QuotaManager::Get();
MOZ_ASSERT(quotaManager);
@ -4508,6 +4536,8 @@ nsresult Connection::FlushOp::DoDatastoreWork() {
Maybe<MutexAutoLock> shadowDatabaseLock;
Maybe<AutoDetach> autoDetach;
if (mShadowWrites) {
MOZ_ASSERT(mConnection->mQuotaClient);
@ -4518,6 +4548,8 @@ nsresult Connection::FlushOp::DoDatastoreWork() {
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
autoDetach.emplace(storageConnection);
}
CachedStatement stmt;
@ -4567,11 +4599,15 @@ nsresult Connection::FlushOp::DoDatastoreWork() {
}
if (mShadowWrites) {
autoDetach->release();
rv = DetachShadowDatabase(storageConnection);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
autoDetach.reset();
shadowDatabaseLock.reset();
}