Bug 870460 - Part 2: Close syncconn for edge cases. r=nwgh

--HG--
extra : source : 50368fa3e040a806a0b86c0c6471055f4cb41ae1
This commit is contained in:
Junior Hsu 2017-10-09 00:19:00 -04:00
parent 6acbefaa2c
commit 0532585ef4
2 changed files with 8 additions and 5 deletions

View File

@ -458,8 +458,9 @@ function* run_test_5(generator)
do_check_eq(do_count_cookies(), 0);
// Close the profile. We do not need to wait for completion, because the
// database has already been closed.
do_close_profile();
// database has already been closed. Ensure the cookie file is unlocked.
do_close_profile(sub_generator);
yield;
// Clean up.
do_get_cookie_file(profile).remove(false);

View File

@ -55,6 +55,7 @@
#include "mozilla/storage.h"
#include "mozilla/AutoRestore.h"
#include "mozilla/FileUtils.h"
#include "mozilla/ScopeExit.h"
#include "mozilla/Telemetry.h"
#include "nsIConsoleService.h"
#include "nsVariant.h"
@ -891,6 +892,10 @@ nsCookieService::TryInitDB(bool aRecreateDB)
NS_ENSURE_SUCCESS(rv, RESULT_RETRY);
}
auto guard = MakeScopeExit([&] {
mDefaultDBState->syncConn = nullptr;
});
bool tableExists = false;
mDefaultDBState->syncConn->TableExists(NS_LITERAL_CSTRING("moz_cookies"),
&tableExists);
@ -1744,7 +1749,6 @@ nsCookieService::CleanupDefaultDBConnection()
// asynchronous operations yet, this will synchronously close it; otherwise,
// it's expected that the caller has performed an AsyncClose prior.
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
@ -2832,8 +2836,6 @@ nsCookieService::Read()
tuple->cookie = GetCookieFromRow(stmt, attrs);
}
mDefaultDBState->syncConn = nullptr;
COOKIE_LOGSTRING(LogLevel::Debug, ("Read(): %zu cookies read", mReadArray.Length()));
return RESULT_OK;