fixes bug 338677 "nsUrlClassifierDBService leaks memory" patch by tony, r=darin

This commit is contained in:
darin%meer.net 2006-05-22 20:28:59 +00:00
Родитель cb4aad3b2e
Коммит 57d0851af2
1 изменённых файлов: 19 добавлений и 10 удалений

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

@ -160,7 +160,7 @@ nsUrlClassifierDBServiceWorker::nsUrlClassifierDBServiceWorker()
} }
nsUrlClassifierDBServiceWorker::~nsUrlClassifierDBServiceWorker() nsUrlClassifierDBServiceWorker::~nsUrlClassifierDBServiceWorker()
{ {
NS_ASSERTION(mConnection != nsnull, NS_ASSERTION(mConnection == nsnull,
"Db connection not closed, leaking memory! Call CloseDb " "Db connection not closed, leaking memory! Call CloseDb "
"to close the connection."); "to close the connection.");
} }
@ -171,6 +171,8 @@ NS_IMETHODIMP
nsUrlClassifierDBServiceWorker::Exists(const nsACString& tableName, nsUrlClassifierDBServiceWorker::Exists(const nsACString& tableName,
const nsACString& key, const nsACString& key,
nsIUrlClassifierCallback *c) { nsIUrlClassifierCallback *c) {
LOG(("Exists\n"));
nsresult rv = OpenDb(); nsresult rv = OpenDb();
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
NS_ERROR("Unable to open database"); NS_ERROR("Unable to open database");
@ -251,6 +253,7 @@ nsUrlClassifierDBServiceWorker::UpdateTables(const nsACString& updateString,
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
// If it's a new table, we must have completed the last table. // If it's a new table, we must have completed the last table.
// Go ahead and post the completion to the UI thread. // Go ahead and post the completion to the UI thread.
// XXX This shouldn't happen before we commit the transaction.
if (lastTableLine.Length() > 0) if (lastTableLine.Length() > 0)
c->HandleEvent(lastTableLine); c->HandleEvent(lastTableLine);
lastTableLine.Assign(line); lastTableLine.Assign(line);
@ -281,8 +284,10 @@ NS_IMETHODIMP
nsUrlClassifierDBServiceWorker::CloseDb() nsUrlClassifierDBServiceWorker::CloseDb()
{ {
if (mConnection != nsnull) { if (mConnection != nsnull) {
NS_RELEASE(mConnection);
delete mConnection; delete mConnection;
mConnection = nsnull; mConnection = nsnull;
LOG(("urlclassifier db closed\n"));
} }
return NS_OK; return NS_OK;
} }
@ -386,6 +391,7 @@ nsUrlClassifierDBServiceWorker::OpenDb()
if (mConnection != nsnull) if (mConnection != nsnull)
return NS_OK; return NS_OK;
LOG(("Opening db\n"));
// Compute database filename // Compute database filename
nsCOMPtr<nsIFile> dbFile; nsCOMPtr<nsIFile> dbFile;
@ -572,19 +578,22 @@ nsUrlClassifierDBService::Shutdown()
if (!gDbBackgroundThread) if (!gDbBackgroundThread)
return NS_OK; return NS_OK;
nsresult rv;
// First close the db connection. // First close the db connection.
if (mWorker) {
nsCOMPtr<nsIUrlClassifierDBServiceWorker> proxy; nsCOMPtr<nsIUrlClassifierDBServiceWorker> proxy;
nsresult rv = NS_GetProxyForObject(gDbBackgroundThread, rv = NS_GetProxyForObject(gDbBackgroundThread,
NS_GET_IID(nsIUrlClassifierDBServiceWorker), NS_GET_IID(nsIUrlClassifierDBServiceWorker),
mWorker, mWorker,
NS_PROXY_ASYNC, NS_PROXY_ASYNC,
getter_AddRefs(proxy)); getter_AddRefs(proxy));
proxy->CloseDb(); proxy->CloseDb();
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
}
LOG(("joining background thread")); LOG(("joining background thread"));
gDbBackgroundThread->Shutdown(); gDbBackgroundThread->Shutdown();
NS_RELEASE(gDbBackgroundThread); NS_RELEASE(gDbBackgroundThread);
return NS_OK; return NS_OK;
} }