From 0d9dcc44264e3c5caf8afa8ba0b06a43d98768cd Mon Sep 17 00:00:00 2001 From: "bienvenu%netscape.com" Date: Sun, 23 Sep 2001 23:42:19 +0000 Subject: [PATCH] fix memory leak of imap headers when move msg filters fire rs=sspitzer 101246 --- mailnews/imap/src/nsImapMoveCoalescer.cpp | 187 +++++++++++----------- 1 file changed, 93 insertions(+), 94 deletions(-) diff --git a/mailnews/imap/src/nsImapMoveCoalescer.cpp b/mailnews/imap/src/nsImapMoveCoalescer.cpp index 7b1ae69de9af..25558d3dd7dc 100644 --- a/mailnews/imap/src/nsImapMoveCoalescer.cpp +++ b/mailnews/imap/src/nsImapMoveCoalescer.cpp @@ -32,113 +32,112 @@ static NS_DEFINE_CID(kCImapService, NS_IMAPSERVICE_CID); nsImapMoveCoalescer::nsImapMoveCoalescer(nsImapMailFolder *sourceFolder, nsIMsgWindow *msgWindow) { - m_sourceFolder = sourceFolder; + m_sourceFolder = sourceFolder; m_msgWindow = msgWindow; NS_IF_ADDREF(msgWindow); - if (sourceFolder) - NS_ADDREF(sourceFolder); + if (sourceFolder) + NS_ADDREF(sourceFolder); } nsImapMoveCoalescer::~nsImapMoveCoalescer() { - NS_IF_RELEASE(m_sourceFolder); - for (PRInt32 i = 0; i < m_sourceKeyArrays.Count(); i++) - { - nsMsgKeyArray *keys = (nsMsgKeyArray *) m_sourceKeyArrays.ElementAt(i); - delete keys; - } + NS_IF_RELEASE(m_sourceFolder); + for (PRInt32 i = 0; i < m_sourceKeyArrays.Count(); i++) + { + nsMsgKeyArray *keys = (nsMsgKeyArray *) m_sourceKeyArrays.ElementAt(i); + delete keys; + } } nsresult nsImapMoveCoalescer::AddMove(nsIMsgFolder *folder, nsMsgKey key) { - if (!m_destFolders) - NS_NewISupportsArray(getter_AddRefs(m_destFolders)); - if (m_destFolders) - { - nsCOMPtr supports = do_QueryInterface(folder); - if (supports) - { - PRInt32 folderIndex = m_destFolders->IndexOf(supports); - nsMsgKeyArray *keysToAdd=nsnull; - if (folderIndex >= 0) - { - keysToAdd = (nsMsgKeyArray *) m_sourceKeyArrays.ElementAt(folderIndex); - } - else - { - m_destFolders->AppendElement(supports); - keysToAdd = new nsMsgKeyArray; - if (!keysToAdd) - return NS_ERROR_OUT_OF_MEMORY; - - m_sourceKeyArrays.AppendElement(keysToAdd); - } - if (keysToAdd) - keysToAdd->Add(key); - return NS_OK; - } - else - return NS_ERROR_NULL_POINTER; - } - else - return NS_ERROR_OUT_OF_MEMORY; - + if (!m_destFolders) + NS_NewISupportsArray(getter_AddRefs(m_destFolders)); + if (m_destFolders) + { + nsCOMPtr supports = do_QueryInterface(folder); + if (supports) + { + PRInt32 folderIndex = m_destFolders->IndexOf(supports); + nsMsgKeyArray *keysToAdd=nsnull; + if (folderIndex >= 0) + { + keysToAdd = (nsMsgKeyArray *) m_sourceKeyArrays.ElementAt(folderIndex); + } + else + { + m_destFolders->AppendElement(supports); + keysToAdd = new nsMsgKeyArray; + if (!keysToAdd) + return NS_ERROR_OUT_OF_MEMORY; + + m_sourceKeyArrays.AppendElement(keysToAdd); + } + if (keysToAdd) + keysToAdd->Add(key); + return NS_OK; + } + else + return NS_ERROR_NULL_POINTER; + } + else + return NS_ERROR_OUT_OF_MEMORY; + } nsresult nsImapMoveCoalescer::PlaybackMoves(nsIEventQueue *eventQueue) { - PRUint32 numFolders; - nsresult rv = NS_OK; - - if (!m_destFolders) - return NS_OK; // nothing to do. - - m_destFolders->Count(&numFolders); - for (PRUint32 i = 0; i < numFolders; i++) - { - nsCOMPtr destSupports = getter_AddRefs(m_destFolders->ElementAt(i)); - nsCOMPtr destFolder(do_QueryInterface(destSupports)); - nsCOMPtr imapService = - do_GetService(kCImapService, &rv); - if (NS_SUCCEEDED(rv) && imapService) - { - nsMsgKeyArray *keysToAdd = (nsMsgKeyArray *) m_sourceKeyArrays.ElementAt(i); - if (keysToAdd) - { - nsCString messageIds; - - m_sourceFolder->AllocateUidStringFromKeys(keysToAdd->GetArray(), keysToAdd->GetSize(), messageIds); - - destFolder->SetNumNewMessages(keysToAdd->GetSize()); - //destFolder->SetBiffState(nsIMsgFolder::nsMsgBiffState_NewMail); - destFolder->SetHasNewMessages(PR_TRUE); - - nsCOMPtr sourceSupports = do_QueryInterface((nsIMsgImapMailFolder *) m_sourceFolder, &rv); - nsCOMPtr urlListener(do_QueryInterface(sourceSupports)); - - nsCOMPtr messages; - NS_NewISupportsArray(getter_AddRefs(messages)); - for (PRUint32 keyIndex = 0; keyIndex < keysToAdd->GetSize(); keyIndex++) - { - nsCOMPtr mailHdr = nsnull; - rv = m_sourceFolder->GetMessageHeader(keysToAdd->ElementAt(keyIndex), getter_AddRefs(mailHdr)); - if (NS_SUCCEEDED(rv) && mailHdr) - { - nsCOMPtr iSupports; - iSupports = do_QueryInterface(mailHdr); - messages->AppendElement(iSupports); - } - } - rv = destFolder->CopyMessages(m_sourceFolder, - messages, PR_TRUE, m_msgWindow, - /*nsIMsgCopyServiceListener* listener*/ nsnull, PR_FALSE, PR_FALSE /*allowUndo*/); -// rv = imapService->OnlineMessageCopy(eventQueue, -// m_sourceFolder, messageIds.get(), -// destFolder, PR_TRUE, PR_TRUE, -// urlListener, nsnull, nsnull); - } - } - } - return rv; + PRUint32 numFolders; + nsresult rv = NS_OK; + + if (!m_destFolders) + return NS_OK; // nothing to do. + + m_destFolders->Count(&numFolders); + for (PRUint32 i = 0; i < numFolders; i++) + { + nsCOMPtr destSupports = getter_AddRefs(m_destFolders->ElementAt(i)); + nsCOMPtr destFolder(do_QueryInterface(destSupports)); + nsCOMPtr imapService = + do_GetService(kCImapService, &rv); + if (NS_SUCCEEDED(rv) && imapService) + { + nsMsgKeyArray *keysToAdd = (nsMsgKeyArray *) m_sourceKeyArrays.ElementAt(i); + if (keysToAdd) + { + nsCString messageIds; + + m_sourceFolder->AllocateUidStringFromKeys(keysToAdd->GetArray(), keysToAdd->GetSize(), messageIds); + + destFolder->SetNumNewMessages(keysToAdd->GetSize()); + //destFolder->SetBiffState(nsIMsgFolder::nsMsgBiffState_NewMail); + destFolder->SetHasNewMessages(PR_TRUE); + + nsCOMPtr sourceSupports = do_QueryInterface((nsIMsgImapMailFolder *) m_sourceFolder, &rv); + nsCOMPtr urlListener(do_QueryInterface(sourceSupports)); + + nsCOMPtr messages; + NS_NewISupportsArray(getter_AddRefs(messages)); + for (PRUint32 keyIndex = 0; keyIndex < keysToAdd->GetSize(); keyIndex++) + { + nsCOMPtr mailHdr = nsnull; + rv = m_sourceFolder->GetMessageHeader(keysToAdd->ElementAt(keyIndex), getter_AddRefs(mailHdr)); + if (NS_SUCCEEDED(rv) && mailHdr) + { + nsCOMPtr iSupports = mailHdr; + messages->AppendElement(iSupports); + } + } + rv = destFolder->CopyMessages(m_sourceFolder, + messages, PR_TRUE, m_msgWindow, + /*nsIMsgCopyServiceListener* listener*/ nsnull, PR_FALSE, PR_FALSE /*allowUndo*/); + // rv = imapService->OnlineMessageCopy(eventQueue, + // m_sourceFolder, messageIds.get(), + // destFolder, PR_TRUE, PR_TRUE, + // urlListener, nsnull, nsnull); + } + } + } + return rv; }