Bug 1340972 - Part 18: Replace more error-prone Addref()/Release() with using RefPtr in mailnews/. r=aceman

This commit is contained in:
Jorg K 2017-09-15 22:31:18 +02:00
Родитель a7987da679
Коммит 6fefbcf208
8 изменённых файлов: 17 добавлений и 28 удалений

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

@ -596,14 +596,14 @@ NS_IMETHODIMP nsAddrDatabase::ForceClosed()
nsCOMPtr<nsIAddrDatabase> aDb(do_QueryInterface(this, &err));
// make sure someone has a reference so object won't get deleted out from under us.
AddRef();
NS_ADDREF_THIS();
NotifyAnnouncerGoingAway();
// OK, remove from cache first and close the store.
RemoveFromCache(this);
err = CloseMDB(false); // since we're about to delete it, no need to commit.
NS_IF_RELEASE(m_mdbStore);
Release();
NS_RELEASE_THIS();
return err;
}

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

@ -465,7 +465,7 @@ nsresult nsFolderCompactState::StartCompacting()
{
nsCOMPtr<nsIURI> notUsed;
ShowCompactingStatusMsg();
AddRef();
NS_ADDREF_THIS();
rv = m_messageService->CopyMessages(m_size, m_keyArray->m_keys.Elements(),
m_folder, this,
false, nullptr, m_window,
@ -474,7 +474,6 @@ nsresult nsFolderCompactState::StartCompacting()
else
{ // no messages to copy with
FinishCompact();
// Release(); // we don't "own" ourselves yet.
}
return rv;
}
@ -777,7 +776,7 @@ nsFolderCompactState::OnStopRequest(nsIRequest *request, nsISupports *ctxt,
ReleaseFolderLock();
}
}
Release(); // kill self
NS_RELEASE_THIS(); // kill self
return status;
}
@ -1145,7 +1144,7 @@ nsOfflineStoreCompactState::OnStopRequest(nsIRequest *request, nsISupports *ctxt
// no more to copy finish it up
ReleaseFolderLock();
FinishCompact();
Release(); // kill self
NS_RELEASE_THIS(); // kill self
}
done:
@ -1153,7 +1152,7 @@ done:
m_status = rv; // set the status to rv so the destructor can remove the
// temp folder and database
ReleaseFolderLock();
Release(); // kill self
NS_RELEASE_THIS(); // kill self
return rv;
}
return rv;
@ -1304,7 +1303,7 @@ nsresult nsOfflineStoreCompactState::StartCompacting()
nsresult rv = NS_OK;
if (m_size > 0 && m_curIndex == 0)
{
AddRef(); // we own ourselves, until we're done, anyway.
NS_ADDREF_THIS(); // we own ourselves, until we're done, anyway.
ShowCompactingStatusMsg();
bool done = false;
rv = CopyNextMessage(done);

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

@ -43,12 +43,12 @@ private:
~ShutdownObserver() {}
void ShutdownServices();
static ShutdownObserver *sShutdownObserver;
static RefPtr<ShutdownObserver> sShutdownObserver;
static bool sShuttingDown;
};
bool ShutdownObserver::sShuttingDown = false;
ShutdownObserver *ShutdownObserver::sShutdownObserver = nullptr;
RefPtr<ShutdownObserver> ShutdownObserver::sShutdownObserver = nullptr;
}
#define MOZ_SERVICE(NAME, TYPE, CONTRACT_ID) \
@ -84,7 +84,6 @@ void ShutdownObserver::EnsureInitialized()
if (!sShutdownObserver)
{
sShutdownObserver = new ShutdownObserver;
sShutdownObserver->AddRef();
nsCOMPtr<nsIObserverService> obs(mozilla::services::GetObserverService());
MOZ_ASSERT(obs, "This should never be null");
obs->AddObserver(sShutdownObserver, "xpcom-shutdown-threads", false);
@ -95,7 +94,6 @@ void ShutdownObserver::ShutdownServices()
{
sShuttingDown = true;
MOZ_ASSERT(sShutdownObserver, "Shutting down twice?");
sShutdownObserver->Release();
sShutdownObserver = nullptr;
#define MOZ_SERVICE(NAME, TYPE, CONTRACT_ID) NS_IF_RELEASE(g##NAME);
#include "mozilla/mailnews/ServiceList.h"

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

@ -211,7 +211,6 @@ nsDBFolderInfo::nsDBFolderInfo(nsMsgDatabase *mdb)
{
nsresult err;
// mdb->AddRef();
err = m_mdb->GetStore()->StringToToken(mdb->GetEnv(), kDBFolderInfoScope, &m_rowScopeToken);
if (NS_SUCCEEDED(err))
{

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

@ -1282,7 +1282,7 @@ NS_IMETHODIMP nsMsgDatabase::ForceClosed()
nsresult err = NS_OK;
// make sure someone has a reference so object won't get deleted out from under us.
AddRef();
NS_ADDREF_THIS();
NotifyAnnouncerGoingAway();
// make sure dbFolderInfo isn't holding onto mork stuff because mork db is going away
if (m_dbFolderInfo)
@ -1311,7 +1311,7 @@ if (m_mdbAllMsgHeadersTable)
// better not be any listeners, because we're going away.
NS_ASSERTION(m_ChangeListeners.IsEmpty(), "shouldn't have any listeners left");
Release();
NS_RELEASE_THIS();
return err;
}
@ -4491,13 +4491,13 @@ nsresult nsMsgDatabase::AddNewThread(nsMsgHdr *msgHdr)
msgHdr->SetThreadId(threadKey);
if (threadHdr)
{
threadHdr->AddRef();
NS_ADDREF(threadHdr);
// err = msgHdr->GetSubject(subject);
// threadHdr->SetThreadKey(msgHdr->m_messageKey);
// threadHdr->SetSubject(subject.get());
// need to add the thread table to the db.
AddToThread(msgHdr, threadHdr, nullptr, false);
threadHdr->Release();
NS_RELEASE(threadHdr);
}
return err;
}

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

@ -29,7 +29,7 @@ nsMsgHdr::nsMsgHdr(nsMsgDatabase *db, nsIMdbRow *dbRow)
m_mdbRow = dbRow;
if(m_mdb)
{
m_mdb->AddRef();
NS_ADDREF(m_mdb); // Released in DTOR.
mdbOid outOid;
if (dbRow && NS_SUCCEEDED(dbRow->GetOid(m_mdb->GetEnv(), &outOid)))
{

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

@ -70,7 +70,5 @@ nsBeckyStringBundle::FormatStringFromName(const char *name,
void
nsBeckyStringBundle::Cleanup(void)
{
if (mBundle)
mBundle->Release();
mBundle = nullptr;
NS_IF_RELEASE(mBundle);
}

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

@ -489,9 +489,7 @@ NS_IMETHODIMP nsPop3IncomingServer::DownloadMailFromServers(nsIPop3IncomingServe
nsIMsgFolder *aFolder,
nsIUrlListener *aUrlListener)
{
nsPop3GetMailChainer *getMailChainer = new nsPop3GetMailChainer;
NS_ENSURE_TRUE(getMailChainer, NS_ERROR_OUT_OF_MEMORY);
getMailChainer->AddRef(); // this object owns itself and releases when done.
RefPtr<nsPop3GetMailChainer> getMailChainer = new nsPop3GetMailChainer;
return getMailChainer->GetNewMailForServers(aServers, aCount, aMsgWindow, aFolder, aUrlListener);
}
@ -534,9 +532,7 @@ nsPop3IncomingServer::GetNewMessages(nsIMsgFolder *aFolder, nsIMsgWindow *aMsgWi
}
if (deferredToAccount.IsEmpty() && !deferredServers.IsEmpty())
{
nsPop3GetMailChainer *getMailChainer = new nsPop3GetMailChainer;
NS_ENSURE_TRUE(getMailChainer, NS_ERROR_OUT_OF_MEMORY);
getMailChainer->AddRef(); // this object owns itself and releases when done.
RefPtr<nsPop3GetMailChainer> getMailChainer = new nsPop3GetMailChainer;
deferredServers.InsertElementAt(0, this);
return getMailChainer->GetNewMailForServers(deferredServers.Elements(),
deferredServers.Length(), aMsgWindow, inbox, aUrlListener);
@ -738,6 +734,5 @@ nsresult nsPop3GetMailChainer::RunNextGetNewMail()
}
}
rv = m_listener ? m_listener->OnStopRunningUrl(nullptr, NS_OK) : NS_OK;
Release(); // release ref to ourself.
return rv;
}