From 2cad0a701451136b8ec078cbc8e342c8026e418d Mon Sep 17 00:00:00 2001 From: "nhotta%netscape.com" Date: Tue, 4 May 1999 22:28:17 +0000 Subject: [PATCH] Fix memory leaks. --- mailnews/compose/src/msgCompGlue.cpp | 8 ++++-- mailnews/compose/src/nsComposeAppCore.cpp | 30 ++++++----------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/mailnews/compose/src/msgCompGlue.cpp b/mailnews/compose/src/msgCompGlue.cpp index 5cc101e327f..fe2bf1a8996 100644 --- a/mailnews/compose/src/msgCompGlue.cpp +++ b/mailnews/compose/src/msgCompGlue.cpp @@ -141,7 +141,9 @@ nsresult ConvertFromUnicode(const nsString aCharset, *outCString = (char *) PR_Malloc(dstLength + 1); if (*outCString != nsnull) { res = encoder->Convert(unichars, &unicharLength, *outCString, &dstLength); - NS_ASSERTION(unicharLength == originalLength, "unicharLength != originalLength"); + // This may also happen for the case like requesting charset "ISO-8859-1" for text in CJK range. + // We don't want assertion for those cases. + // NS_ASSERTION(unicharLength == originalLength, "unicharLength != originalLength"); } } if (*outCString != nsnull) { @@ -189,6 +191,7 @@ nsresult ConvertToUnicode(const nsString aCharset, // convert to unicode res = decoder->Convert(unichars, 0, &unicharLength, inCString, 0, &srcLen); outString.SetString(unichars, unicharLength); + PR_Free(unichars); } else { res = NS_ERROR_OUT_OF_MEMORY; @@ -257,7 +260,7 @@ char * INTL_GetDefaultMailCharset() retVal = PL_strdup(prefValue); } else - retVal = PL_strdup("us-ascii"); + retVal = PL_strdup("us-ascii"); } return (nsnull != retVal) ? retVal : PL_strdup("us-ascii"); @@ -274,6 +277,7 @@ PRBool INTL_stateful_charset(const char *charset) // This is expensive (both memory and performance). // The check would be very simple if applied to an unicode text (e.g. nsString or utf-8). // Possible optimazaion is to search ESC(0x1B) in case of iso-2022-jp and iso-2022-kr. +// Or convert and check line by line. PRBool INTL_7bit_data_part(const char *charset, const char *inString, const PRUint32 size) { char *aCString; diff --git a/mailnews/compose/src/nsComposeAppCore.cpp b/mailnews/compose/src/nsComposeAppCore.cpp index a5872708645..ddbf28cb6c9 100644 --- a/mailnews/compose/src/nsComposeAppCore.cpp +++ b/mailnews/compose/src/nsComposeAppCore.cpp @@ -333,28 +333,10 @@ nsComposeAppCore::ConstructAfterJavaScript(nsIWebShell *aWebShell) nsresult nsComposeAppCore::SetDocumentCharset(class nsString const & aCharset) { - nsresult res = NS_OK; - if (nsnull != mWindow) - { - nsIDOMDocument* domDoc; - res = mWindow->GetDocument(&domDoc); - if (NS_SUCCEEDED(res) && nsnull != domDoc) - { - nsIDocument * doc; - res = domDoc->QueryInterface(kIDocumentIID,(void**)&doc); - if (NS_SUCCEEDED(res) && nsnull != doc) - { - doc->SetDocumentCharacterSet(aCharset); - NS_RELEASE(doc); - } - - NS_RELEASE(domDoc); - } - } // Set charset, this will be used for the MIME charset labeling. mMsgCompFields->SetCharacterSet(nsAutoCString(aCharset), NULL); - return res; + return NS_OK; } nsIScriptContext * @@ -635,6 +617,7 @@ nsComposeAppCore::NewMessage(nsAutoString& aUrl, { nsresult rv; nsString controllerCID; + char *default_mail_charset = nsnull; mArgs = args; NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv); @@ -661,9 +644,12 @@ nsComposeAppCore::NewMessage(nsAutoString& aUrl, 615, // width 650); // height - // Get the default charset from pref, use this as a mail charset. - // TODO: For reply/forward, original charset need to be used instead. - mMsgCompFields->SetCharacterSet(INTL_GetDefaultMailCharset(), NULL); + // Get the default charset from pref, use this as a mail charset. + default_mail_charset = INTL_GetDefaultMailCharset(); + if (NULL != default_mail_charset) { + mMsgCompFields->SetCharacterSet(default_mail_charset, NULL); + PR_Free(default_mail_charset); + } if (tree && nodeList && msgAppCore) { nsCOMPtr object;