Bug 1357366 - Avoid a possible crash loop in Places Database corruption handling. r=past
MozReview-Commit-ID: BIN3ji68nAY
--- a/toolkit/components/places/Database.cpp
+++ b/toolkit/components/places/Database.cpp
@@ -810,19 +810,23 @@ Database::BackupAndReplaceDatabaseFile(n
return NS_OK;
}
nsresult
Database::ForceCrashAndReplaceDatabase(const nsCString& aReason)
{
Preferences::SetBool(PREF_FORCE_DATABASE_REPLACEMENT, true);
- // We could force an application restart here, but we'd like to get these
- // cases reported to us, so let's force a crash instead.
- MOZ_CRASH_UNSAFE_OOL(aReason.get());
+ // Ensure that prefs get saved, or we could crash before storing them.
+ nsIPrefService* prefService = Preferences::GetService();
+ if (prefService && NS_SUCCEEDED(prefService->SavePrefFile(nullptr))) {
+ // We could force an application restart here, but we'd like to get these
+ // cases reported to us, so let's force a crash instead.
+ MOZ_CRASH_UNSAFE_OOL(aReason.get());
+ }
return NS_ERROR_FAILURE;
}
nsresult
Database::InitSchema(bool* aDatabaseMigrated)
{
MOZ_ASSERT(NS_IsMainThread());
*aDatabaseMigrated = false;