diff --git a/netwerk/cookie/nsCookieService.cpp b/netwerk/cookie/nsCookieService.cpp index e78b50d527..74683e7a49 100644 --- a/netwerk/cookie/nsCookieService.cpp +++ b/netwerk/cookie/nsCookieService.cpp @@ -49,6 +49,7 @@ #include "mozilla/storage.h" #include "mozilla/AutoRestore.h" #include "mozilla/FileUtils.h" +#include "mozilla/ScopeExit.h" #include "nsIConsoleService.h" #include "nsVariant.h" @@ -845,6 +846,10 @@ nsCookieService::TryInitDB(bool aRecreateDB) getter_AddRefs(mDefaultDBState->syncConn)); NS_ENSURE_SUCCESS(rv, RESULT_RETRY); + auto guard = MakeScopeExit([&] { + mDefaultDBState->syncConn = nullptr; + }); + bool tableExists = false; mDefaultDBState->syncConn->TableExists(NS_LITERAL_CSTRING("moz_cookies"), &tableExists); @@ -1596,8 +1601,8 @@ nsCookieService::CleanupDefaultDBConnection() // Null out the database connections. If 'dbConn' has not been used for any // asynchronous operations yet, this will synchronously close it; otherwise, // it's expected that the caller has performed an AsyncClose prior. + // Note 'syncConn' is auto-closed on scope exit. mDefaultDBState->dbConn = nullptr; - mDefaultDBState->syncConn = nullptr; // Manually null out our listeners. This is necessary because they hold a // strong ref to the DBState itself. They'll stay alive until whatever @@ -2619,7 +2624,7 @@ nsCookieService::Read() tuple->cookie = GetCookieFromRow(stmt, attrs); } - mDefaultDBState->syncConn = nullptr; + // Note: 'syncConn' is auto-closed on scope exit. COOKIE_LOGSTRING(LogLevel::Debug, ("Read(): %zu cookies read", mReadArray.Length()));