bug 801466 - part 5 uriloader/ and rdf/ r=ehsan
authorTrevor Saunders <trev.saunders@gmail.com>
Sat, 01 Dec 2012 19:57:25 -0500
changeset 114735 a253800d2e570ff974fb50452c9e36c69aa817fc
parent 114734 0d2b2b1018a744581db0e7bb2fd5b8ffe79ec7d3
child 114736 e7ac63e9cbf1f438eb752bf24584e01e76fd2a16
push id1226
push userrcampbell@mozilla.com
push dateTue, 04 Dec 2012 20:18:07 +0000
treeherderfx-team@e8f0504ccbb9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs801466
milestone20.0a1
bug 801466 - part 5 uriloader/ and rdf/ r=ehsan
rdf/base/src/nsRDFContentSink.cpp
rdf/datasource/src/nsFileSystemDataSource.cpp
uriloader/exthandler/nsExternalHelperAppService.cpp
--- a/rdf/base/src/nsRDFContentSink.cpp
+++ b/rdf/base/src/nsRDFContentSink.cpp
@@ -51,17 +51,16 @@
 #include "nsIRDFXMLSink.h"
 #include "nsIServiceManager.h"
 #include "nsIURL.h"
 #include "nsIXMLContentSink.h"
 #include "nsRDFCID.h"
 #include "nsTArray.h"
 #include "nsXPIDLString.h"
 #include "prlog.h"
-#include "prmem.h"
 #include "rdf.h"
 #include "rdfutil.h"
 #include "nsReadableUtils.h"
 #include "nsIExpatSink.h"
 #include "nsCRT.h"
 #include "nsIAtom.h"
 #include "nsStaticAtom.h"
 #include "nsIScriptError.h"
@@ -351,17 +350,17 @@ RDFContentSinkImpl::~RDFContentSinkImpl(
             }
 #endif
 
             NS_IF_RELEASE(resource);
         }
 
         delete mContextStack;
     }
-    PR_FREEIF(mText);
+    moz_free(mText);
 
 
     if (--gRefCnt == 0) {
         NS_IF_RELEASE(gRDFService);
         NS_IF_RELEASE(gRDFContainerUtils);
         NS_IF_RELEASE(kRDF_type);
         NS_IF_RELEASE(kRDF_instanceOf);
         NS_IF_RELEASE(kRDF_Alt);
@@ -758,17 +757,17 @@ RDFContentSinkImpl::FlushText()
 }
 
 
 nsresult
 RDFContentSinkImpl::AddText(const PRUnichar* aText, int32_t aLength)
 {
     // Create buffer when we first need it
     if (0 == mTextSize) {
-        mText = (PRUnichar *) PR_MALLOC(sizeof(PRUnichar) * 4096);
+        mText = (PRUnichar *) moz_malloc(sizeof(PRUnichar) * 4096);
         if (!mText) {
             return NS_ERROR_OUT_OF_MEMORY;
         }
         mTextSize = 4096;
     }
 
     // Copy data from string into our buffer; grow the buffer as needed.
     // It never shrinks, but since the content sink doesn't stick around,
@@ -776,17 +775,17 @@ RDFContentSinkImpl::AddText(const PRUnic
     int32_t amount = mTextSize - mTextLength;
     if (amount < aLength) {
         // Grow the buffer by at least a factor of two to prevent thrashing.
         // Since PR_REALLOC will leave mText intact if the call fails,
         // don't clobber mText or mTextSize until the new mem is allocated.
         int32_t newSize = (2 * mTextSize > (mTextSize + aLength)) ?
                           (2 * mTextSize) : (mTextSize + aLength);
         PRUnichar* newText = 
-            (PRUnichar *) PR_REALLOC(mText, sizeof(PRUnichar) * newSize);
+            (PRUnichar *) moz_realloc(mText, sizeof(PRUnichar) * newSize);
         if (!newText)
             return NS_ERROR_OUT_OF_MEMORY;
         mTextSize = newSize;
         mText = newText;
     }
     memcpy(&mText[mTextLength], aText, sizeof(PRUnichar) * aLength);
     mTextLength += aLength;
 
--- a/rdf/datasource/src/nsFileSystemDataSource.cpp
+++ b/rdf/datasource/src/nsFileSystemDataSource.cpp
@@ -13,23 +13,16 @@
 #include <stdio.h>
 #include "nsIEnumerator.h"
 #include "nsIRDFDataSource.h"
 #include "nsIRDFObserver.h"
 #include "nsIServiceManager.h"
 #include "nsXPIDLString.h"
 #include "nsRDFCID.h"
 #include "rdfutil.h"
-#include "plhash.h"
-#include "plstr.h"
-#include "prlong.h"
-#include "prlog.h"
-#include "prmem.h"
-#include "prprf.h"
-#include "prio.h"
 #include "rdf.h"
 #include "nsEnumeratorUtils.h"
 #include "nsIURL.h"
 #include "nsIFileURL.h"
 #include "nsNetUtil.h"
 #include "nsIChannel.h"
 #include "nsIFile.h"
 #include "nsEscape.h"
@@ -866,64 +859,58 @@ FileSystemDataSource::GetVolumeList(nsIS
 
     nsCOMPtr<nsIRDFResource> vol;
 
 #ifdef XP_WIN
 
     int32_t         driveType;
     PRUnichar       drive[32];
     int32_t         volNum;
-    char            *url;
 
     for (volNum = 0; volNum < 26; volNum++)
     {
         swprintf( drive, L"%c:\\", volNum + (PRUnichar)'A');
 
         driveType = GetDriveTypeW(drive);
         if (driveType != DRIVE_UNKNOWN && driveType != DRIVE_NO_ROOT_DIR)
         {
-            if (nullptr != (url = PR_smprintf("file:///%c|/", volNum + 'A')))
-            {
-                rv = mRDFService->GetResource(nsDependentCString(url),
-                                              getter_AddRefs(vol));
-                PR_Free(url);
+          nsAutoCString url;
+          url.AppendPrintf("file:///%c|/", volNum + 'A');
+          rv = mRDFService->GetResource(url, getter_AddRefs(vol));
+          if (NS_FAILED(rv))
+            return rv;
 
-                if (NS_FAILED(rv)) return rv;
-                volumes->AppendElement(vol);
-            }
+          volumes->AppendElement(vol);
         }
     }
 #endif
 
 #ifdef XP_UNIX
     mRDFService->GetResource(NS_LITERAL_CSTRING("file:///"), getter_AddRefs(vol));
     volumes->AppendElement(vol);
 #endif
 
 #ifdef XP_OS2
     ULONG ulDriveNo = 0;
     ULONG ulDriveMap = 0;
-    char *url;
 
     rv = DosQueryCurrentDisk(&ulDriveNo, &ulDriveMap);
     if (NS_FAILED(rv))
         return rv;
 
     for (int volNum = 0; volNum < 26; volNum++)
     {
         if (((ulDriveMap << (31 - volNum)) >> 31))
         {
-            if (nullptr != (url = PR_smprintf("file:///%c|/", volNum + 'A')))
-            {
-                rv = mRDFService->GetResource(nsDependentCString(url), getter_AddRefs(vol));
-                PR_Free(url);
+          nsAutoCString url;
+          url.AppendPrintf("file:///%c|/", volNum + 'A');
+          rv = mRDFService->GetResource(nsDependentCString(url), getter_AddRefs(vol));
 
-                if (NS_FAILED(rv)) return rv;
-                volumes->AppendElement(vol);
-            }
+          if (NS_FAILED(rv)) return rv;
+          volumes->AppendElement(vol);
         }
 
     }
 #endif
 
     return NS_NewArrayEnumerator(aResult, volumes);
 }
 
--- a/uriloader/exthandler/nsExternalHelperAppService.cpp
+++ b/uriloader/exthandler/nsExternalHelperAppService.cpp
@@ -6,31 +6,33 @@
 
 #ifdef MOZ_LOGGING
 #define FORCE_PR_LOG
 #endif
 
 #include "base/basictypes.h"
 
 /* This must occur *after* base/basictypes.h to avoid typedefs conflicts. */
+#include "mozilla/Base64.h"
 #include "mozilla/Util.h"
 
 #include "mozilla/dom/ContentChild.h"
 #include "nsXULAppAPI.h"
 
 #include "nsExternalHelperAppService.h"
 #include "nsCExternalHandlerService.h"
 #include "nsIURI.h"
 #include "nsIURL.h"
 #include "nsIFile.h"
 #include "nsIFileURL.h"
 #include "nsIChannel.h"
 #include "nsIDirectoryService.h"
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsICategoryManager.h"
+#include "nsDependentSubstring.h"
 #include "nsXPIDLString.h"
 #include "nsUnicharUtils.h"
 #include "nsIStringEnumerator.h"
 #include "nsMemory.h"
 #include "nsIStreamListener.h"
 #include "nsIMIMEService.h"
 #include "nsILoadGroup.h"
 #include "nsIWebProgressListener.h"
@@ -92,18 +94,16 @@
 #include "nsIDOMWindow.h"
 #include "nsIDocShell.h"
 
 #include "nsCRT.h"
 
 #include "nsLocalHandlerApp.h"
 
 #include "nsIRandomGenerator.h"
-#include "plbase64.h"
-#include "prmem.h"
 
 #include "ContentChild.h"
 #include "nsXULAppAPI.h"
 #include "nsPIDOMWindow.h"
 #include "nsIDocShellTreeOwner.h"
 #include "nsIDocShellTreeItem.h"
 #include "ExternalHelperAppChild.h"
 
@@ -1300,30 +1300,24 @@ nsresult nsExternalAppHandler::SetUpTemp
   nsCOMPtr<nsIRandomGenerator> rg =
     do_GetService("@mozilla.org/security/random-generator;1", &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   uint8_t *buffer;
   rv = rg->GenerateRandomBytes(requiredBytesLength, &buffer);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  char *b64 = PL_Base64Encode(reinterpret_cast<const char *>(buffer),
-                              requiredBytesLength, nullptr);
+  nsAutoCString tempLeafName;
+  nsDependentCSubstring randomData(reinterpret_cast<const char*>(buffer), requiredBytesLength);
+  rv = Base64Encode(randomData, tempLeafName);
   NS_Free(buffer);
   buffer = nullptr;
-
-  if (!b64)
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_SUCCESS(rv, rv);
 
-  NS_ASSERTION(strlen(b64) >= wantedFileNameLength,
-               "not enough bytes produced for conversion!");
-
-  nsAutoCString tempLeafName(b64, wantedFileNameLength);
-  PR_Free(b64);
-  b64 = nullptr;
+  tempLeafName.Truncate(wantedFileNameLength);
 
   // Base64 characters are alphanumeric (a-zA-Z0-9) and '+' and '/', so we need
   // to replace illegal characters -- notably '/'
   tempLeafName.ReplaceChar(FILE_PATH_SEPARATOR FILE_ILLEGAL_CHARACTERS, '_');
 
   // now append our extension.
   nsAutoCString ext;
   mMimeInfo->GetPrimaryExtension(ext);