fix ref count leak of msgdb when marking local msgs read r=naving, sr=sspitzer a=asa 128910

This commit is contained in:
bienvenu%netscape.com 2002-03-06 01:24:13 +00:00
Родитель 4e4b80e712
Коммит b5f916d0df
1 изменённых файлов: 62 добавлений и 65 удалений

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

@ -703,73 +703,70 @@ NS_IMETHODIMP nsMailDatabase::ListAllOfflineDeletes(nsMsgKeyArray *offlineDelete
/* static */ /* static */
nsresult nsMailDatabase::SetFolderInfoValid(nsFileSpec *folderName, int num, int numunread) nsresult nsMailDatabase::SetFolderInfoValid(nsFileSpec *folderName, int num, int numunread)
{ {
nsLocalFolderSummarySpec summarySpec(*folderName); nsLocalFolderSummarySpec summarySpec(*folderName);
nsFileSpec summaryPath(summarySpec); nsFileSpec summaryPath(summarySpec);
nsresult err = NS_OK; nsresult err = NS_OK;
PRBool bOpenedDB = PR_FALSE; PRBool bOpenedDB = PR_FALSE;
if (!folderName->Exists()) if (!folderName->Exists())
return NS_MSG_ERROR_FOLDER_SUMMARY_MISSING; return NS_MSG_ERROR_FOLDER_SUMMARY_MISSING;
// should we have type safe downcast methods again? // should we have type safe downcast methods again?
nsMailDatabase *pMessageDB = (nsMailDatabase *) nsMailDatabase::FindInCache(summaryPath); nsMailDatabase *pMessageDB = (nsMailDatabase *) nsMailDatabase::FindInCache(summaryPath);
if (pMessageDB == NULL) if (pMessageDB == nsnull)
{ {
pMessageDB = new nsMailDatabase(); pMessageDB = new nsMailDatabase();
if(!pMessageDB) if(!pMessageDB)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
pMessageDB->m_folderSpec = new nsLocalFolderSummarySpec(); pMessageDB->m_folderSpec = new nsLocalFolderSummarySpec();
if(!pMessageDB->m_folderSpec) if(!pMessageDB->m_folderSpec)
{ {
delete pMessageDB; delete pMessageDB;
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }
*(pMessageDB->m_folderSpec) = summarySpec; *(pMessageDB->m_folderSpec) = summarySpec;
// ### this does later stuff (marks latered messages unread), which may be a problem // ### this does later stuff (marks latered messages unread), which may be a problem
err = pMessageDB->OpenMDB(summaryPath, PR_FALSE); err = pMessageDB->OpenMDB(summaryPath, PR_FALSE);
if (err != NS_OK) if (err != NS_OK)
{ {
delete pMessageDB; delete pMessageDB;
pMessageDB = NULL; pMessageDB = nsnull;
} }
bOpenedDB = PR_TRUE; bOpenedDB = PR_TRUE;
} }
else
pMessageDB->AddRef(); if (pMessageDB == nsnull)
{
if (pMessageDB == NULL)
{
#ifdef DEBUG #ifdef DEBUG
printf("Exception opening summary file\n"); printf("Exception opening summary file\n");
#endif #endif
return NS_MSG_ERROR_FOLDER_SUMMARY_OUT_OF_DATE; return NS_MSG_ERROR_FOLDER_SUMMARY_OUT_OF_DATE;
} }
{ {
nsFileSpec::TimeStamp actualFolderTimeStamp; nsFileSpec::TimeStamp actualFolderTimeStamp;
folderName->GetModDate(actualFolderTimeStamp) ; folderName->GetModDate(actualFolderTimeStamp) ;
pMessageDB->m_dbFolderInfo->SetFolderSize(folderName->GetFileSize()); pMessageDB->m_dbFolderInfo->SetFolderSize(folderName->GetFileSize());
pMessageDB->m_dbFolderInfo->SetFolderDate(actualFolderTimeStamp); pMessageDB->m_dbFolderInfo->SetFolderDate(actualFolderTimeStamp);
pMessageDB->m_dbFolderInfo->ChangeNumVisibleMessages(num); pMessageDB->m_dbFolderInfo->ChangeNumVisibleMessages(num);
pMessageDB->m_dbFolderInfo->ChangeNumNewMessages(numunread); pMessageDB->m_dbFolderInfo->ChangeNumNewMessages(numunread);
pMessageDB->m_dbFolderInfo->ChangeNumMessages(num); pMessageDB->m_dbFolderInfo->ChangeNumMessages(num);
} }
// if we opened the db, then we'd better close it. Otherwise, we found it in the cache, // if we opened the db, then we'd better close it. Otherwise, we found it in the cache,
// so just commit and release. // so just commit and release.
if (bOpenedDB) if (bOpenedDB)
{ {
pMessageDB->Close(PR_TRUE); pMessageDB->Close(PR_TRUE);
} }
else if (pMessageDB) else if (pMessageDB)
{ {
err = pMessageDB->Commit(nsMsgDBCommitType::kLargeCommit); err = pMessageDB->Commit(nsMsgDBCommitType::kLargeCommit);
pMessageDB->Release(); pMessageDB->Release();
} }
return err; return err;
} }