Bug 614756. r=Olli.Pettay a=roc
authorMats Palmgren <matspal@gmail.com>
Wed, 08 Dec 2010 03:17:33 +0100
changeset 58806 90fecee8a8c330147ff83a38a0faec4a2549a8d7
parent 58805 ed4d22fad16a943e489e82c58405c2c6212c6124
child 58807 64e893aa5d9559619fa9330cbd952ffd7c704f9c
push idunknown
push userunknown
push dateunknown
reviewersOlli.Pettay, roc
bugs614756
milestone2.0b8pre
Bug 614756. r=Olli.Pettay a=roc
docshell/base/nsDocShell.cpp
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -4067,43 +4067,50 @@ nsDocShell::LoadErrorPage(nsIURI *aURI, 
     }
     else
     {
         return NS_ERROR_INVALID_POINTER;
     }
 
     // Create a URL to pass all the error information through to the page.
 
-    char *escapedUrl = nsEscape(url.get(), url_Path);
-    char *escapedCharset = nsEscape(charset.get(), url_Path);
-    char *escapedError = nsEscape(NS_ConvertUTF16toUTF8(aErrorType).get(), url_Path);
-    char *escapedDescription = nsEscape(NS_ConvertUTF16toUTF8(aDescription).get(), url_Path);
-    char *escapedCSSClass = nsEscape(aCSSClass, url_Path);
-
+#undef SAFE_ESCAPE
+#define SAFE_ESCAPE(cstring, escArg1, escArg2)  \
+    {                                           \
+        char* s = nsEscape(escArg1, escArg2);   \
+        if (!s)                                 \
+            return NS_ERROR_OUT_OF_MEMORY;      \
+        cstring.Adopt(s);                       \
+    }
+    nsCString escapedUrl, escapedCharset, escapedError, escapedDescription,
+              escapedCSSClass;
+    SAFE_ESCAPE(escapedUrl, url.get(), url_Path);
+    SAFE_ESCAPE(escapedCharset, charset.get(), url_Path);
+    SAFE_ESCAPE(escapedError,
+                NS_ConvertUTF16toUTF8(aErrorType).get(), url_Path);
+    SAFE_ESCAPE(escapedDescription,
+                NS_ConvertUTF16toUTF8(aDescription).get(), url_Path);
+    if (aCSSClass) {
+        SAFE_ESCAPE(escapedCSSClass, aCSSClass, url_Path);
+    }
     nsCString errorPageUrl("about:");
     errorPageUrl.AppendASCII(aErrorPage);
     errorPageUrl.AppendLiteral("?e=");
 
-    errorPageUrl.AppendASCII(escapedError);
+    errorPageUrl.AppendASCII(escapedError.get());
     errorPageUrl.AppendLiteral("&u=");
-    errorPageUrl.AppendASCII(escapedUrl);
-    if (escapedCSSClass && escapedCSSClass[0]) {
+    errorPageUrl.AppendASCII(escapedUrl.get());
+    if (!escapedCSSClass.IsEmpty()) {
         errorPageUrl.AppendASCII("&s=");
-        errorPageUrl.AppendASCII(escapedCSSClass);
+        errorPageUrl.AppendASCII(escapedCSSClass.get());
     }
     errorPageUrl.AppendLiteral("&c=");
-    errorPageUrl.AppendASCII(escapedCharset);
+    errorPageUrl.AppendASCII(escapedCharset.get());
     errorPageUrl.AppendLiteral("&d=");
-    errorPageUrl.AppendASCII(escapedDescription);
-
-    nsMemory::Free(escapedDescription);
-    nsMemory::Free(escapedError);
-    nsMemory::Free(escapedUrl);
-    nsMemory::Free(escapedCharset);
-    nsMemory::Free(escapedCSSClass);
+    errorPageUrl.AppendASCII(escapedDescription.get());
 
     nsCOMPtr<nsIURI> errorPageURI;
     nsresult rv = NS_NewURI(getter_AddRefs(errorPageURI), errorPageUrl);
     NS_ENSURE_SUCCESS(rv, rv);
 
     return InternalLoad(errorPageURI, nsnull, nsnull,
                         INTERNAL_LOAD_FLAGS_INHERIT_OWNER, nsnull, nsnull,
                         nsnull, nsnull, LOAD_ERROR_PAGE,