Issue #2672 - Part 2: Auto-close syncConn for edge cases.

This commit is contained in:
Moonchild 2024-12-22 16:05:33 +01:00 committed by roytam1
commit fe53a0bb1c

View file

@ -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()));