diff --git a/extensions/cookie/nsPermissionManager.cpp b/extensions/cookie/nsPermissionManager.cpp index 67eb216175d7..cdfe21bbc3ac 100644 --- a/extensions/cookie/nsPermissionManager.cpp +++ b/extensions/cookie/nsPermissionManager.cpp @@ -620,6 +620,20 @@ nsPermissionManager::RemoveAll() return rv; } +void +nsPermissionManager::CloseDB() +{ + // Null the statements, this will finalize them. + mStmtInsert = nsnull; + mStmtDelete = nsnull; + mStmtUpdate = nsnull; + if (mDBConn) { + mozilla::DebugOnly rv = mDBConn->Close(); + MOZ_ASSERT(NS_SUCCEEDED(rv)); + mDBConn = nsnull; + } +} + nsresult nsPermissionManager::RemoveAllInternal() { @@ -629,10 +643,7 @@ nsPermissionManager::RemoveAllInternal() if (mDBConn) { nsresult rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING("DELETE FROM moz_hosts")); if (NS_FAILED(rv)) { - mStmtInsert = nsnull; - mStmtDelete = nsnull; - mStmtUpdate = nsnull; - mDBConn = nsnull; + CloseDB(); rv = InitDB(true); return rv; } @@ -792,12 +803,7 @@ NS_IMETHODIMP nsPermissionManager::Observe(nsISupports *aSubject, const char *aT } else { RemoveAllFromMemory(); } - if (mDBConn) { - // Null the statements, this will finalize them. - mStmtInsert = nsnull; - mStmtDelete = nsnull; - mStmtUpdate = nsnull; - } + CloseDB(); } else if (!nsCRT::strcmp(aTopic, "profile-do-change")) { // the profile has already changed; init the db from the new location diff --git a/extensions/cookie/nsPermissionManager.h b/extensions/cookie/nsPermissionManager.h index 3b9149e17dc4..117a68874072 100644 --- a/extensions/cookie/nsPermissionManager.h +++ b/extensions/cookie/nsPermissionManager.h @@ -222,6 +222,10 @@ private: PRInt64 aExpireTime, const PRUnichar *aData); void NotifyObservers(nsIPermission *aPermission, const PRUnichar *aData); + + // Finalize all statements, close the DB and null it. + void CloseDB(); + nsresult RemoveAllInternal(); nsresult RemoveAllFromMemory(); nsresult NormalizeToACE(nsCString &aHost);