Bug 711447 - Close connection in nsPermissionManager. r=dwitte.

--HG--
extra : rebase_source : 0df435f943142b7a09de36fdb03e01114ef20f15
This commit is contained in:
Rafael Ávila de Espíndola 2011-12-21 17:04:49 -05:00
Родитель 101f2ecf55
Коммит df24103177
2 изменённых файлов: 20 добавлений и 10 удалений

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

@ -620,6 +620,20 @@ nsPermissionManager::RemoveAll()
return rv; return rv;
} }
void
nsPermissionManager::CloseDB()
{
// Null the statements, this will finalize them.
mStmtInsert = nsnull;
mStmtDelete = nsnull;
mStmtUpdate = nsnull;
if (mDBConn) {
mozilla::DebugOnly<nsresult> rv = mDBConn->Close();
MOZ_ASSERT(NS_SUCCEEDED(rv));
mDBConn = nsnull;
}
}
nsresult nsresult
nsPermissionManager::RemoveAllInternal() nsPermissionManager::RemoveAllInternal()
{ {
@ -629,10 +643,7 @@ nsPermissionManager::RemoveAllInternal()
if (mDBConn) { if (mDBConn) {
nsresult rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING("DELETE FROM moz_hosts")); nsresult rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING("DELETE FROM moz_hosts"));
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
mStmtInsert = nsnull; CloseDB();
mStmtDelete = nsnull;
mStmtUpdate = nsnull;
mDBConn = nsnull;
rv = InitDB(true); rv = InitDB(true);
return rv; return rv;
} }
@ -792,12 +803,7 @@ NS_IMETHODIMP nsPermissionManager::Observe(nsISupports *aSubject, const char *aT
} else { } else {
RemoveAllFromMemory(); RemoveAllFromMemory();
} }
if (mDBConn) { CloseDB();
// Null the statements, this will finalize them.
mStmtInsert = nsnull;
mStmtDelete = nsnull;
mStmtUpdate = nsnull;
}
} }
else if (!nsCRT::strcmp(aTopic, "profile-do-change")) { else if (!nsCRT::strcmp(aTopic, "profile-do-change")) {
// the profile has already changed; init the db from the new location // the profile has already changed; init the db from the new location

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

@ -222,6 +222,10 @@ private:
PRInt64 aExpireTime, PRInt64 aExpireTime,
const PRUnichar *aData); const PRUnichar *aData);
void NotifyObservers(nsIPermission *aPermission, const PRUnichar *aData); void NotifyObservers(nsIPermission *aPermission, const PRUnichar *aData);
// Finalize all statements, close the DB and null it.
void CloseDB();
nsresult RemoveAllInternal(); nsresult RemoveAllInternal();
nsresult RemoveAllFromMemory(); nsresult RemoveAllFromMemory();
nsresult NormalizeToACE(nsCString &aHost); nsresult NormalizeToACE(nsCString &aHost);