From 4d3224d77cc8a9ea0e202337c1846c42c106187d Mon Sep 17 00:00:00 2001 From: "mscott%netscape.com" Date: Mon, 22 Nov 1999 23:33:24 +0000 Subject: [PATCH] Bug #1966 --> properly ref count the url listeners for send and post this means never calling delete directly on the objects like we were before. A nsCAutoString tweak... r=rhp --- mailnews/compose/src/nsMsgSend.cpp | 30 +++++++++++++----------------- mailnews/compose/src/nsMsgSend.h | 5 +++-- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/mailnews/compose/src/nsMsgSend.cpp b/mailnews/compose/src/nsMsgSend.cpp index 6a3f93ea4cf..6a6406f82b4 100644 --- a/mailnews/compose/src/nsMsgSend.cpp +++ b/mailnews/compose/src/nsMsgSend.cpp @@ -149,8 +149,6 @@ nsMsgComposeAndSend::nsMsgComposeAndSend() : mCompFields = nsnull; /* Where to send the message once it's done */ mListenerArray = nsnull; mListenerArrayCount = 0; - mNewsPostListener = nsnull; - mMailSendListener = nsnull; mSendMailAlso = PR_FALSE; mOutputFile = nsnull; @@ -2312,9 +2310,6 @@ MailDeliveryCallback(nsIURI *aUrl, nsresult aExitCode, void *tagData) nsMsgComposeAndSend *ptr = (nsMsgComposeAndSend *) tagData; ptr->DeliverAsMailExit(aUrl, aExitCode); - if (ptr->mMailSendListener) { - delete ptr->mMailSendListener; - } NS_RELEASE(ptr); } @@ -2332,8 +2327,6 @@ NewsDeliveryCallback(nsIURI *aUrl, nsresult aExitCode, void *tagData) ptr->DeliverAsNewsExit(aUrl, aExitCode, ptr->mSendMailAlso); - if (ptr->mNewsPostListener) - delete ptr->mNewsPostListener; NS_RELEASE(ptr); } @@ -2477,7 +2470,9 @@ nsMsgComposeAndSend::DeliverFileAsMail() NS_WITH_SERVICE(nsISmtpService, smtpService, kSmtpServiceCID, &rv); if (NS_SUCCEEDED(rv) && smtpService) { - mMailSendListener = new nsMsgDeliveryListener(MailDeliveryCallback, nsMailDelivery, this); + nsMsgDeliveryListener * aListener = new nsMsgDeliveryListener(MailDeliveryCallback, nsMailDelivery, this); + mMailSendListener = do_QueryInterface(aListener); + if (!mMailSendListener) { // RICHIE_TODO - message loss here? @@ -2488,9 +2483,9 @@ nsMsgComposeAndSend::DeliverFileAsMail() // Note: Don't do a SetMsgComposeAndSendObject since we are in the same thread, and // using callbacks for notification // - NS_ADDREF_THIS(); - nsCOMPtr aFileSpec; - NS_NewFileSpecWithSpec(*mTempFileSpec, getter_AddRefs(aFileSpec)); + NS_ADDREF_THIS(); // why are we forcing an addref on ourselves? this doesn't look right to me + nsCOMPtr aFileSpec; + NS_NewFileSpecWithSpec(*mTempFileSpec, getter_AddRefs(aFileSpec)); rv = smtpService->SendMailMessage(aFileSpec, buf, mUserIdentity, mMailSendListener, nsnull, nsnull); } @@ -2509,7 +2504,9 @@ nsMsgComposeAndSend::DeliverFileAsNews() if (NS_SUCCEEDED(rv) && nntpService) { - mNewsPostListener = new nsMsgDeliveryListener(NewsDeliveryCallback, nsNewsDelivery, this); + nsMsgDeliveryListener * aListener = new nsMsgDeliveryListener(NewsDeliveryCallback, nsNewsDelivery, this); + mNewsPostListener = do_QueryInterface(aListener); + if (!mNewsPostListener) { // RICHIE_TODO - message loss here? @@ -2520,8 +2517,8 @@ nsMsgComposeAndSend::DeliverFileAsNews() // Note: Don't do a SetMsgComposeAndSendObject since we are in the same thread, and // using callbacks for notification // - NS_ADDREF_THIS(); - AddRef(); + NS_ADDREF_THIS(); // two addrefs on ourselves? This looks bogus too.... + AddRef(); nsCOMPtrfileToPost; rv = NS_NewFileSpecWithSpec(*mTempFileSpec, getter_AddRefs(fileToPost)); @@ -3599,7 +3596,7 @@ nsMsgComposeAndSend::StartMessageCopyOperation(nsIFileSpec *aFileSpec, nsMsgDeliverMode mode, char *dest_uri) { - char *uri = nsnull; + nsCAutoString uri; mCopyObj = new nsMsgCopy(); if (!mCopyObj) @@ -3612,11 +3609,10 @@ nsMsgComposeAndSend::StartMessageCopyOperation(nsIFileSpec *aFileSpec, nsresult rv; if (dest_uri && *dest_uri) - uri = PL_strdup(dest_uri); + uri = dest_uri; else uri = GetFolderURIFromUserPrefs(mode, mUserIdentity); rv = mCopyObj->StartCopyOperation(mUserIdentity, aFileSpec, mode, this, uri, mMsgToReplace); - PR_FREEIF(uri); return rv; } diff --git a/mailnews/compose/src/nsMsgSend.h b/mailnews/compose/src/nsMsgSend.h index 5f3794b306c..e9a6bf86a2c 100644 --- a/mailnews/compose/src/nsMsgSend.h +++ b/mailnews/compose/src/nsMsgSend.h @@ -136,6 +136,7 @@ #include "nsIMessage.h" #include "nsIDOMNode.h" #include "nsIEditorShell.h" +#include "nsIUrlListener.h" #if 0 #include "nsMsgCopy.h" #endif @@ -345,8 +346,8 @@ public: PRInt32 mListenerArrayCount; // we need two, in the case where we are sending and posting the same message - nsMsgDeliveryListener *mNewsPostListener; - nsMsgDeliveryListener *mMailSendListener; + nsCOMPtr mNewsPostListener; + nsCOMPtr mMailSendListener; PRBool mSendMailAlso; nsIFileSpec *mReturnFileSpec; // a holder for file spec's to be returned to caller