Bug 1410794 - Change some |string| occurrences in nsIPrefBranch.idl to |ACString|. r=erahm.
☠☠ backed out by 23f3b04d3e13 ☠ ☠
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 25 Oct 2017 10:22:38 +1100
changeset 685889 3d0093f961eec929caa370444cd0f7fcbfbc82bc
parent 685888 da9f271dcedd86b7f5533d283210bf378e8f9b51
child 685890 86644d65eb6f83ef0f89132e2a47eae8fd52d546
child 686116 9fc12ae8a2e7f9eb857e9e19fa32a767dfb11661
child 686555 afd5a8ef98afe1f73b2a5b12136ffc39d6b5f58a
push id86026
push usernnethercote@mozilla.com
push dateWed, 25 Oct 2017 04:01:04 +0000
reviewerserahm
bugs1410794
milestone58.0a1
Bug 1410794 - Change some |string| occurrences in nsIPrefBranch.idl to |ACString|. r=erahm. This makes the code nicer. In particular, it removes many getter_Copies() calls. The patch also converts a lot of nsCStrings to nsAutoCString, which will avoid heap allocation in the common case. The patch also renames PREF_CopyCharPref() as PREF_GetCStringPref(), because it's actually getting a string, not a char, and that matches the existing GetCString() and GetDefaultCString() methods. Correspondingly, it also renames PREF_SetCharPref() as PREF_SetCStringPref(). The |aPrefName| arguments in nsIPrefBranch.idl remain as |string| because they almost always involve passing in C string literals, and passing "foo" is much nicer than passing NS_LITERAL_CSTRING("foo"). It's worth noting that early versions of this patch used |AUTF8String| instead of |ACString|. But it turns out that libpref stores prefs internally as Latin1. And |ACString| is compatible with Latin1 but |AUTF8String| isn't, because non-ASCII Latin1 strings are not valid UTF-8!
browser/components/dirprovider/DirectoryProvider.cpp
chrome/nsChromeRegistryChrome.cpp
extensions/auth/nsAuthGSSAPI.cpp
extensions/pref/autoconfig/src/nsAutoConfig.cpp
extensions/pref/autoconfig/src/nsReadConfig.cpp
extensions/spellcheck/hunspell/glue/mozHunspell.cpp
media/mtransport/nricectx.cpp
modules/libpref/Preferences.cpp
modules/libpref/nsIPrefBranch.idl
netwerk/base/nsIOService.cpp
netwerk/base/nsProtocolProxyService.cpp
netwerk/dns/nsDNSService2.cpp
netwerk/dns/nsIDNService.cpp
netwerk/protocol/ftp/nsFtpConnectionThread.cpp
netwerk/protocol/gio/nsGIOProtocolHandler.cpp
netwerk/protocol/http/HttpAuthUtils.cpp
netwerk/protocol/http/nsHttpHandler.cpp
toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
toolkit/components/url-classifier/nsUrlClassifierUtils.cpp
toolkit/xre/nsAppRunner.cpp
--- a/browser/components/dirprovider/DirectoryProvider.cpp
+++ b/browser/components/dirprovider/DirectoryProvider.cpp
@@ -104,19 +104,19 @@ AppendDistroSearchDirs(nsIProperties* aD
 
     nsCOMPtr<nsIFile> localePlugins;
     rv = searchPlugins->Clone(getter_AddRefs(localePlugins));
     if (NS_FAILED(rv))
       return;
 
     localePlugins->AppendNative(NS_LITERAL_CSTRING("locale"));
 
-    nsCString defLocale;
+    nsAutoCString defLocale;
     rv = prefs->GetCharPref("distribution.searchplugins.defaultLocale",
-                            getter_Copies(defLocale));
+                            defLocale);
     if (NS_SUCCEEDED(rv)) {
 
       nsCOMPtr<nsIFile> defLocalePlugins;
       rv = localePlugins->Clone(getter_AddRefs(defLocalePlugins));
       if (NS_SUCCEEDED(rv)) {
 
         defLocalePlugins->AppendNative(defLocale);
         rv = defLocalePlugins->Exists(&exists);
--- a/chrome/nsChromeRegistryChrome.cpp
+++ b/chrome/nsChromeRegistryChrome.cpp
@@ -123,18 +123,18 @@ nsChromeRegistryChrome::Init()
     } else {
       prefs = do_QueryInterface(prefserv);
     }
   }
 
   if (!prefs) {
     NS_WARNING("Could not get pref service!");
   } else {
-    nsCString provider;
-    rv = prefs->GetCharPref(SELECTED_SKIN_PREF, getter_Copies(provider));
+    nsAutoCString provider;
+    rv = prefs->GetCharPref(SELECTED_SKIN_PREF, provider);
     if (NS_SUCCEEDED(rv))
       mSelectedSkin = provider;
 
     rv = prefs->AddObserver(SELECTED_SKIN_PREF, this, true);
   }
 
   nsCOMPtr<nsIObserverService> obsService = mozilla::services::GetObserverService();
   if (obsService) {
@@ -270,18 +270,18 @@ nsChromeRegistryChrome::Observe(nsISuppo
 
   if (!strcmp(NS_PREFBRANCH_PREFCHANGE_TOPIC_ID, aTopic)) {
     nsCOMPtr<nsIPrefBranch> prefs (do_QueryInterface(aSubject));
     NS_ASSERTION(prefs, "Bad observer call!");
 
     NS_ConvertUTF16toUTF8 pref(someData);
 
     if (pref.EqualsLiteral(SELECTED_SKIN_PREF)) {
-      nsCString provider;
-      rv = prefs->GetCharPref(pref.get(), getter_Copies(provider));
+      nsAutoCString provider;
+      rv = prefs->GetCharPref(pref.get(), provider);
       if (NS_FAILED(rv)) {
         NS_ERROR("Couldn't get new skin pref!");
         return rv;
       }
 
       mSelectedSkin = provider;
       RefreshSkins();
     } else {
--- a/extensions/auth/nsAuthGSSAPI.cpp
+++ b/extensions/auth/nsAuthGSSAPI.cpp
@@ -97,20 +97,20 @@ static PRLibrary* gssLibrary = nullptr;
 static PRFuncPtr KLCacheHasValidTicketsPtr;
 #define KLCacheHasValidTickets_ptr \
         ((KLCacheHasValidTickets_type)*KLCacheHasValidTicketsPtr)
 #endif
 
 static nsresult
 gssInit()
 {
-    nsCString libPath;
+    nsAutoCString libPath;
     nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
     if (prefs) {
-        prefs->GetCharPref(kNegotiateAuthGssLib, getter_Copies(libPath));
+        prefs->GetCharPref(kNegotiateAuthGssLib, libPath);
         prefs->GetBoolPref(kNegotiateAuthNativeImp, &gssNativeImp);
     }
 
     PRLibrary *lib = nullptr;
 
     if (!libPath.IsEmpty()) {
         LOG(("Attempting to load user specified library [%s]\n", libPath.get()));
         gssNativeImp = false;
--- a/extensions/pref/autoconfig/src/nsAutoConfig.cpp
+++ b/extensions/pref/autoconfig/src/nsAutoConfig.cpp
@@ -453,49 +453,48 @@ nsresult nsAutoConfig::writeFailoverFile
     outStr->Close();
     return rv;
 }
 
 nsresult nsAutoConfig::getEmailAddr(nsACString & emailAddr)
 {
 
     nsresult rv;
-    nsCString prefValue;
+    nsAutoCString prefValue;
 
     /* Getting an email address through set of three preferences:
        First getting a default account with
        "mail.accountmanager.defaultaccount"
        second getting an associated id with the default account
        Third getting an email address with id
     */
 
     rv = mPrefBranch->GetCharPref("mail.accountmanager.defaultaccount",
-                                  getter_Copies(prefValue));
+                                  prefValue);
     if (NS_SUCCEEDED(rv) && !prefValue.IsEmpty()) {
         emailAddr = NS_LITERAL_CSTRING("mail.account.") +
             prefValue + NS_LITERAL_CSTRING(".identities");
         rv = mPrefBranch->GetCharPref(PromiseFlatCString(emailAddr).get(),
-                                      getter_Copies(prefValue));
+                                      prefValue);
         if (NS_FAILED(rv) || prefValue.IsEmpty())
             return PromptForEMailAddress(emailAddr);
         int32_t commandIndex = prefValue.FindChar(',');
         if (commandIndex != kNotFound)
           prefValue.Truncate(commandIndex);
         emailAddr = NS_LITERAL_CSTRING("mail.identity.") +
             prefValue + NS_LITERAL_CSTRING(".useremail");
         rv = mPrefBranch->GetCharPref(PromiseFlatCString(emailAddr).get(),
-                                      getter_Copies(prefValue));
+                                      prefValue);
         if (NS_FAILED(rv)  || prefValue.IsEmpty())
             return PromptForEMailAddress(emailAddr);
         emailAddr = prefValue;
     }
     else {
         // look for 4.x pref in case we just migrated.
-        rv = mPrefBranch->GetCharPref("mail.identity.useremail",
-                                  getter_Copies(prefValue));
+        rv = mPrefBranch->GetCharPref("mail.identity.useremail", prefValue);
         if (NS_SUCCEEDED(rv) && !prefValue.IsEmpty())
             emailAddr = prefValue;
         else
             PromptForEMailAddress(emailAddr);
     }
 
     return NS_OK;
 }
--- a/extensions/pref/autoconfig/src/nsReadConfig.cpp
+++ b/extensions/pref/autoconfig/src/nsReadConfig.cpp
@@ -110,35 +110,35 @@ NS_IMETHODIMP nsReadConfig::Observe(nsIS
     }
     return rv;
 }
 
 
 nsresult nsReadConfig::readConfigFile()
 {
     nsresult rv = NS_OK;
-    nsCString lockFileName;
-    nsCString lockVendor;
+    nsAutoCString lockFileName;
+    nsAutoCString lockVendor;
     uint32_t fileNameLen = 0;
 
     nsCOMPtr<nsIPrefBranch> defaultPrefBranch;
     nsCOMPtr<nsIPrefService> prefService =
         do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
     if (NS_FAILED(rv))
         return rv;
 
     rv = prefService->GetDefaultBranch(nullptr, getter_AddRefs(defaultPrefBranch));
     if (NS_FAILED(rv))
         return rv;
 
     // This preference is set in the all.js or all-ns.js (depending whether
     // running mozilla or netscp6)
 
     rv = defaultPrefBranch->GetCharPref("general.config.filename",
-                                  getter_Copies(lockFileName));
+                                        lockFileName);
 
 
     MOZ_LOG(MCD, LogLevel::Debug, ("general.config.filename = %s\n", lockFileName.get()));
     if (NS_FAILED(rv))
         return rv;
 
     // This needs to be read only once.
     //
@@ -174,43 +174,40 @@ nsresult nsReadConfig::readConfigFile()
     rv = openAndEvaluateJSFile(lockFileName.get(), obscureValue, true, true);
     if (NS_FAILED(rv))
     {
       MOZ_LOG(MCD, LogLevel::Debug, ("error evaluating .cfg file %s %" PRIx32 "\n",
                                      lockFileName.get(), static_cast<uint32_t>(rv)));
       return rv;
     }
 
-    rv = prefBranch->GetCharPref("general.config.filename",
-                                  getter_Copies(lockFileName));
+    rv = prefBranch->GetCharPref("general.config.filename", lockFileName);
     if (NS_FAILED(rv))
         // There is NO REASON we should ever get here. This is POST reading
         // of the config file.
         return NS_ERROR_FAILURE;
 
 
-    rv = prefBranch->GetCharPref("general.config.vendor",
-                                  getter_Copies(lockVendor));
+    rv = prefBranch->GetCharPref("general.config.vendor", lockVendor);
     // If vendor is not nullptr, do this check
     if (NS_SUCCEEDED(rv)) {
 
         fileNameLen = strlen(lockFileName.get());
 
         // lockVendor and lockFileName should be the same with the addtion of
         // .cfg to the filename by checking this post reading of the cfg file
         // this value can be set within the cfg file adding a level of security.
 
         if (PL_strncmp(lockFileName.get(), lockVendor.get(), fileNameLen - 4) != 0)
             return NS_ERROR_FAILURE;
     }
 
     // get the value of the autoconfig url
-    nsCString urlName;
-    rv = prefBranch->GetCharPref("autoadmin.global_config_url",
-                                  getter_Copies(urlName));
+    nsAutoCString urlName;
+    rv = prefBranch->GetCharPref("autoadmin.global_config_url", urlName);
     if (NS_SUCCEEDED(rv) && !urlName.IsEmpty()) {
 
         // Instantiating nsAutoConfig object if the pref is present
         mAutoConfig = do_CreateInstance(NS_AUTOCONFIG_CONTRACTID, &rv);
         if (NS_FAILED(rv))
             return NS_ERROR_OUT_OF_MEMORY;
 
         rv = mAutoConfig->SetConfigURL(urlName.get());
--- a/extensions/spellcheck/hunspell/glue/mozHunspell.cpp
+++ b/extensions/spellcheck/hunspell/glue/mozHunspell.cpp
@@ -309,18 +309,18 @@ mozHunspell::LoadDictionaryList(bool aNo
 
   // find built in dictionaries, or dictionaries specified in
   // spellchecker.dictionary_path in prefs
   nsCOMPtr<nsIFile> dictDir;
 
   // check preferences first
   nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
   if (prefs) {
-    nsCString extDictPath;
-    rv = prefs->GetCharPref("spellchecker.dictionary_path", getter_Copies(extDictPath));
+    nsAutoCString extDictPath;
+    rv = prefs->GetCharPref("spellchecker.dictionary_path", extDictPath);
     if (NS_SUCCEEDED(rv)) {
       // set the spellchecker.dictionary_path
       rv = NS_NewNativeLocalFile(extDictPath, true, getter_AddRefs(dictDir));
     }
   }
   if (!dictDir) {
     // spellcheck.dictionary_path not found, set internal path
     rv = dirSvc->Get(DICTIONARY_SEARCH_DIRECTORY,
--- a/media/mtransport/nricectx.cpp
+++ b/media/mtransport/nricectx.cpp
@@ -452,17 +452,17 @@ NrIceCtx::InitializeGlobals(bool allow_l
         branch->GetIntPref(
             "media.peerconnection.ice.tcp_so_sock_count",
             &ice_tcp_so_sock_count);
         branch->GetIntPref(
             "media.peerconnection.ice.tcp_listen_backlog",
             &ice_tcp_listen_backlog);
         branch->GetCharPref(
             "media.peerconnection.ice.force_interface",
-            getter_Copies(force_net_interface));
+            force_net_interface);
       }
     }
 
     NR_reg_set_uint4((char *)"stun.client.maximum_transmits",
                      stun_client_maximum_transmits);
     NR_reg_set_uint4((char *)NR_ICE_REG_TRICKLE_GRACE_PERIOD,
                      ice_trickle_grace_period);
     NR_reg_set_int4((char *)NR_ICE_REG_ICE_TCP_SO_SOCK_COUNT,
@@ -628,35 +628,35 @@ NrIceCtx::Initialize(const std::string& 
   if (generating_trickle()) {
     r = nr_ice_ctx_set_trickle_cb(ctx_, &NrIceCtx::trickle_cb, this);
     if (r) {
       MOZ_MTLOG(ML_ERROR, "Couldn't set trickle cb for '" << name_ << "'");
       return false;
     }
   }
 
-  nsCString mapping_type;
-  nsCString filtering_type;
+  nsAutoCString mapping_type;
+  nsAutoCString filtering_type;
   bool block_udp = false;
   bool block_tcp = false;
 
   nsresult rv;
   nsCOMPtr<nsIPrefService> pref_service =
     do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
 
   if (NS_SUCCEEDED(rv)) {
     nsCOMPtr<nsIPrefBranch> pref_branch;
     rv = pref_service->GetBranch(nullptr, getter_AddRefs(pref_branch));
     if (NS_SUCCEEDED(rv)) {
       rv = pref_branch->GetCharPref(
           "media.peerconnection.nat_simulator.mapping_type",
-          getter_Copies(mapping_type));
+          mapping_type);
       rv = pref_branch->GetCharPref(
           "media.peerconnection.nat_simulator.filtering_type",
-          getter_Copies(filtering_type));
+          filtering_type);
       rv = pref_branch->GetBoolPref(
           "media.peerconnection.nat_simulator.block_udp",
           &block_udp);
       rv = pref_branch->GetBoolPref(
           "media.peerconnection.nat_simulator.block_tcp",
           &block_tcp);
     }
   }
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -480,41 +480,46 @@ StrEscape(const char* aOriginal, nsCStri
 // If aSetDefault is set to true however, it sets the default value. This will
 // only affect the program behavior if the user does not have a value saved
 // over it for the particular preference. In addition, these will never be
 // saved out to disk.
 //
 // Each set returns PREF_VALUECHANGED if the user value changed (triggering a
 // callback), or PREF_NOERROR if the value was unchanged.
 static nsresult
-PREF_SetCharPref(const char* aPrefName, const char* aValue, bool aSetDefault)
-{
-  if (strlen(aValue) > MAX_PREF_LENGTH) {
+PREF_SetCStringPref(const char* aPrefName,
+                    const nsACString& aValue,
+                    bool aSetDefault)
+{
+  if (aValue.Length() > MAX_PREF_LENGTH) {
     return NS_ERROR_ILLEGAL_VALUE;
   }
 
+  // It's ok to stash a pointer to the temporary PromiseFlatCString's chars in
+  // pref because pref_HashPref() duplicates those chars.
   PrefValue pref;
-  pref.mStringVal = const_cast<char*>(aValue);
+  const nsCString& flat = PromiseFlatCString(aValue);
+  pref.mStringVal = const_cast<char*>(flat.get());
 
   return pref_HashPref(
     aPrefName, pref, PrefType::String, aSetDefault ? kPrefSetDefault : 0);
 }
 
-// Like PREF_SetCharPref(), but for integers.
+// Like PREF_SetCStringPref(), but for integers.
 static nsresult
 PREF_SetIntPref(const char* aPrefName, int32_t aValue, bool aSetDefault)
 {
   PrefValue pref;
   pref.mIntVal = aValue;
 
   return pref_HashPref(
     aPrefName, pref, PrefType::Int, aSetDefault ? kPrefSetDefault : 0);
 }
 
-// Like PREF_SetCharPref(), but for booleans.
+// Like PREF_SetCStringPref(), but for booleans.
 static nsresult
 PREF_SetBoolPref(const char* aPrefName, bool aValue, bool aSetDefault)
 {
   PrefValue pref;
   pref.mBoolVal = aValue;
 
   return pref_HashPref(
     aPrefName, pref, PrefType::Bool, aSetDefault ? kPrefSetDefault : 0);
@@ -530,18 +535,17 @@ static nsresult
 SetPrefValue(const char* aPrefName,
              const dom::PrefValue& aValue,
              WhichValue aWhich)
 {
   bool setDefault = (aWhich == DEFAULT_VALUE);
 
   switch (aValue.type()) {
     case dom::PrefValue::TnsCString:
-      return PREF_SetCharPref(
-        aPrefName, aValue.get_nsCString().get(), setDefault);
+      return PREF_SetCStringPref(aPrefName, aValue.get_nsCString(), setDefault);
 
     case dom::PrefValue::Tint32_t:
       return PREF_SetIntPref(aPrefName, aValue.get_int32_t(), setDefault);
 
     case dom::PrefValue::Tbool:
       return PREF_SetBoolPref(aPrefName, aValue.get_bool(), setDefault);
 
     default:
@@ -713,19 +717,20 @@ PREF_HasUserPref(const char* aPrefName)
   if (!gHashTable) {
     return false;
   }
 
   PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
   return pref && pref->mPrefFlags.HasUserValue();
 }
 
-// This function allocates memory and the caller is responsible for freeing it.
 static nsresult
-PREF_CopyCharPref(const char* aPrefName, char** aValueOut, bool aGetDefault)
+PREF_GetCStringPref(const char* aPrefName,
+                    nsACString& aValueOut,
+                    bool aGetDefault)
 {
   if (!gHashTable) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   nsresult rv = NS_ERROR_UNEXPECTED;
   char* stringVal;
   PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
@@ -734,17 +739,17 @@ PREF_CopyCharPref(const char* aPrefName,
     if (aGetDefault || pref->mPrefFlags.IsLocked() ||
         !pref->mPrefFlags.HasUserValue()) {
       stringVal = pref->mDefaultPref.mStringVal;
     } else {
       stringVal = pref->mUserPref.mStringVal;
     }
 
     if (stringVal) {
-      *aValueOut = moz_xstrdup(stringVal);
+      aValueOut = stringVal;
       rv = NS_OK;
     }
   }
 
   return rv;
 }
 
 // Get an int preference. This function takes a dotted notation of the
@@ -2228,24 +2233,23 @@ protected:
   };
 
   virtual ~nsPrefBranch();
 
   nsresult GetDefaultFromPropertiesFile(const char* aPrefName,
                                         nsAString& aReturn);
 
   // As SetCharPref, but without any check on the length of |aValue|.
-  nsresult SetCharPrefInternal(const char* aPrefName, const char* aValue);
+  nsresult SetCharPrefInternal(const char* aPrefName, const nsACString& aValue);
 
   // Reject strings that are more than 1Mb, warn if strings are more than 16kb.
   nsresult CheckSanityOfStringLength(const char* aPrefName,
                                      const nsAString& aValue);
   nsresult CheckSanityOfStringLength(const char* aPrefName,
                                      const nsACString& aValue);
-  nsresult CheckSanityOfStringLength(const char* aPrefName, const char* aValue);
   nsresult CheckSanityOfStringLength(const char* aPrefName,
                                      const uint32_t aLength);
 
   void RemoveExpiredCallback(PrefCallback* aCallback);
 
   PrefName GetPrefName(const char* aPrefName) const;
 
   void FreeObserverList(void);
@@ -2328,21 +2332,19 @@ NS_IMPL_RELEASE(nsPrefBranch)
 NS_INTERFACE_MAP_BEGIN(nsPrefBranch)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIPrefBranch)
   NS_INTERFACE_MAP_ENTRY(nsIPrefBranch)
   NS_INTERFACE_MAP_ENTRY(nsIObserver)
   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
 NS_INTERFACE_MAP_END
 
 NS_IMETHODIMP
-nsPrefBranch::GetRoot(char** aRoot)
-{
-  NS_ENSURE_ARG_POINTER(aRoot);
-
-  *aRoot = ToNewCString(mPrefRoot);
+nsPrefBranch::GetRoot(nsACString& aRoot)
+{
+  aRoot = mPrefRoot;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsPrefBranch::GetPrefType(const char* aPrefName, int32_t* aRetVal)
 {
   NS_ENSURE_ARG(aPrefName);
   const PrefName& pref = GetPrefName(aPrefName);
@@ -2418,79 +2420,77 @@ nsPrefBranch::GetFloatPrefWithDefault(co
 }
 
 NS_IMETHODIMP
 nsPrefBranch::GetFloatPref(const char* aPrefName, float* aRetVal)
 {
   NS_ENSURE_ARG(aPrefName);
 
   nsAutoCString stringVal;
-  nsresult rv = GetCharPref(aPrefName, getter_Copies(stringVal));
+  nsresult rv = GetCharPref(aPrefName, stringVal);
   if (NS_SUCCEEDED(rv)) {
     *aRetVal = stringVal.ToFloat(&rv);
   }
 
   return rv;
 }
 
 NS_IMETHODIMP
 nsPrefBranch::GetCharPrefWithDefault(const char* aPrefName,
-                                     const char* aDefaultValue,
+                                     const nsACString& aDefaultValue,
                                      uint8_t aArgc,
-                                     char** aRetVal)
+                                     nsACString& aRetVal)
 {
   nsresult rv = GetCharPref(aPrefName, aRetVal);
 
   if (NS_FAILED(rv) && aArgc == 1) {
-    NS_ENSURE_ARG(aDefaultValue);
-    *aRetVal = moz_xstrdup(aDefaultValue);
+    aRetVal = aDefaultValue;
     return NS_OK;
   }
 
   return rv;
 }
 
 NS_IMETHODIMP
-nsPrefBranch::GetCharPref(const char* aPrefName, char** aRetVal)
+nsPrefBranch::GetCharPref(const char* aPrefName, nsACString& aRetVal)
 {
   NS_ENSURE_ARG(aPrefName);
   const PrefName& pref = GetPrefName(aPrefName);
-  return PREF_CopyCharPref(pref.get(), aRetVal, mIsDefault);
+  return PREF_GetCStringPref(pref.get(), aRetVal, mIsDefault);
 }
 
 NS_IMETHODIMP
-nsPrefBranch::SetCharPref(const char* aPrefName, const char* aValue)
+nsPrefBranch::SetCharPref(const char* aPrefName, const nsACString& aValue)
 {
   nsresult rv = CheckSanityOfStringLength(aPrefName, aValue);
   if (NS_FAILED(rv)) {
     return rv;
   }
   return SetCharPrefInternal(aPrefName, aValue);
 }
 
 nsresult
-nsPrefBranch::SetCharPrefInternal(const char* aPrefName, const char* aValue)
-
+nsPrefBranch::SetCharPrefInternal(const char* aPrefName,
+                                  const nsACString& aValue)
 {
   ENSURE_MAIN_PROCESS("SetCharPref", aPrefName);
   NS_ENSURE_ARG(aPrefName);
-  NS_ENSURE_ARG(aValue);
 
   const PrefName& pref = GetPrefName(aPrefName);
-  return PREF_SetCharPref(pref.get(), aValue, mIsDefault);
+  return PREF_SetCStringPref(pref.get(), aValue, mIsDefault);
 }
 
 NS_IMETHODIMP
 nsPrefBranch::GetStringPref(const char* aPrefName,
                             const nsACString& aDefaultValue,
                             uint8_t aArgc,
                             nsACString& aRetVal)
 {
   nsCString utf8String;
-  nsresult rv = GetCharPref(aPrefName, getter_Copies(utf8String));
+  nsresult rv = GetCharPref(aPrefName, utf8String);
   if (NS_SUCCEEDED(rv)) {
     aRetVal = utf8String;
     return rv;
   }
 
   if (aArgc == 1) {
     aRetVal = aDefaultValue;
     return NS_OK;
@@ -2502,17 +2502,17 @@ nsPrefBranch::GetStringPref(const char* 
 NS_IMETHODIMP
 nsPrefBranch::SetStringPref(const char* aPrefName, const nsACString& aValue)
 {
   nsresult rv = CheckSanityOfStringLength(aPrefName, aValue);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
-  return SetCharPrefInternal(aPrefName, PromiseFlatCString(aValue).get());
+  return SetCharPrefInternal(aPrefName, aValue);
 }
 
 NS_IMETHODIMP
 nsPrefBranch::GetIntPrefWithDefault(const char* aPrefName,
                                     int32_t aDefaultValue,
                                     uint8_t aArgc,
                                     int32_t* aRetVal)
 {
@@ -2546,17 +2546,17 @@ nsPrefBranch::SetIntPref(const char* aPr
 NS_IMETHODIMP
 nsPrefBranch::GetComplexValue(const char* aPrefName,
                               const nsIID& aType,
                               void** aRetVal)
 {
   NS_ENSURE_ARG(aPrefName);
 
   nsresult rv;
-  nsCString utf8String;
+  nsAutoCString utf8String;
 
   // we have to do this one first because it's different than all the rest
   if (aType.Equals(NS_GET_IID(nsIPrefLocalizedString))) {
     nsCOMPtr<nsIPrefLocalizedString> theString(
       do_CreateInstance(NS_PREFLOCALIZEDSTRING_CONTRACTID, &rv));
     if (NS_FAILED(rv)) {
       return rv;
     }
@@ -2577,31 +2577,31 @@ nsPrefBranch::GetComplexValue(const char
     // value we pulled in at the top of this function
     if (bNeedDefault) {
       nsAutoString utf16String;
       rv = GetDefaultFromPropertiesFile(pref.get(), utf16String);
       if (NS_SUCCEEDED(rv)) {
         theString->SetData(utf16String);
       }
     } else {
-      rv = GetCharPref(aPrefName, getter_Copies(utf8String));
+      rv = GetCharPref(aPrefName, utf8String);
       if (NS_SUCCEEDED(rv)) {
         theString->SetData(NS_ConvertUTF8toUTF16(utf8String));
       }
     }
 
     if (NS_SUCCEEDED(rv)) {
       theString.forget(reinterpret_cast<nsIPrefLocalizedString**>(aRetVal));
     }
 
     return rv;
   }
 
   // if we can't get the pref, there's no point in being here
-  rv = GetCharPref(aPrefName, getter_Copies(utf8String));
+  rv = GetCharPref(aPrefName, utf8String);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   if (aType.Equals(NS_GET_IID(nsIFile))) {
     if (XRE_IsContentProcess()) {
       NS_ERROR("cannot get nsIFile pref from content process");
       return NS_ERROR_NOT_AVAILABLE;
@@ -2703,26 +2703,16 @@ nsPrefBranch::GetComplexValue(const char
   }
 
   NS_WARNING("nsPrefBranch::GetComplexValue - Unsupported interface type");
   return NS_NOINTERFACE;
 }
 
 nsresult
 nsPrefBranch::CheckSanityOfStringLength(const char* aPrefName,
-                                        const char* aValue)
-{
-  if (!aValue) {
-    return NS_OK;
-  }
-  return CheckSanityOfStringLength(aPrefName, strlen(aValue));
-}
-
-nsresult
-nsPrefBranch::CheckSanityOfStringLength(const char* aPrefName,
                                         const nsAString& aValue)
 {
   return CheckSanityOfStringLength(aPrefName, aValue.Length());
 }
 
 nsresult
 nsPrefBranch::CheckSanityOfStringLength(const char* aPrefName,
                                         const nsACString& aValue)
@@ -2791,17 +2781,17 @@ nsPrefBranch::SetComplexValue(const char
     nsCOMPtr<nsIFile> file = do_QueryInterface(aValue);
     if (!file) {
       return NS_NOINTERFACE;
     }
 
     nsAutoCString descriptorString;
     rv = file->GetPersistentDescriptor(descriptorString);
     if (NS_SUCCEEDED(rv)) {
-      rv = SetCharPrefInternal(aPrefName, descriptorString.get());
+      rv = SetCharPrefInternal(aPrefName, descriptorString);
     }
     return rv;
   }
 
   if (aType.Equals(NS_GET_IID(nsIRelativeFilePref))) {
     nsCOMPtr<nsIRelativeFilePref> relFilePref = do_QueryInterface(aValue);
     if (!relFilePref) {
       return NS_NOINTERFACE;
@@ -2835,35 +2825,34 @@ nsPrefBranch::SetComplexValue(const char
       return rv;
     }
 
     nsAutoCString descriptorString;
     descriptorString.Append('[');
     descriptorString.Append(relativeToKey);
     descriptorString.Append(']');
     descriptorString.Append(relDescriptor);
-    return SetCharPrefInternal(aPrefName, descriptorString.get());
+    return SetCharPrefInternal(aPrefName, descriptorString);
   }
 
   if (aType.Equals(NS_GET_IID(nsISupportsString)) ||
       aType.Equals(NS_GET_IID(nsIPrefLocalizedString))) {
     nsCOMPtr<nsISupportsString> theString = do_QueryInterface(aValue);
 
     if (theString) {
       nsString wideString;
 
       rv = theString->GetData(wideString);
       if (NS_SUCCEEDED(rv)) {
         // Check sanity of string length before any lengthy conversion
         rv = CheckSanityOfStringLength(aPrefName, wideString);
         if (NS_FAILED(rv)) {
           return rv;
         }
-        rv = SetCharPrefInternal(aPrefName,
-                                 NS_ConvertUTF16toUTF8(wideString).get());
+        rv = SetCharPrefInternal(aPrefName, NS_ConvertUTF16toUTF8(wideString));
       }
     }
     return rv;
   }
 
   NS_WARNING("nsPrefBranch::SetComplexValue - Unsupported interface type");
   return NS_NOINTERFACE;
 }
@@ -3144,19 +3133,18 @@ nsPrefBranch::RemoveExpiredCallback(Pref
 }
 
 nsresult
 nsPrefBranch::GetDefaultFromPropertiesFile(const char* aPrefName,
                                            nsAString& aReturn)
 {
   // The default value contains a URL to a .properties file.
 
-  nsCString propertyFileURL;
-  nsresult rv =
-    PREF_CopyCharPref(aPrefName, getter_Copies(propertyFileURL), true);
+  nsAutoCString propertyFileURL;
+  nsresult rv = PREF_GetCStringPref(aPrefName, propertyFileURL, true);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   nsCOMPtr<nsIStringBundleService> bundleService =
     mozilla::services::GetStringBundleService();
   if (!bundleService) {
     return NS_ERROR_FAILURE;
@@ -3973,26 +3961,26 @@ Preferences::Init()
     for (unsigned int i = 0; i < gInitPrefs->Length(); i++) {
       Preferences::SetPreference(gInitPrefs->ElementAt(i));
     }
     delete gInitPrefs;
     gInitPrefs = nullptr;
     return Ok();
   }
 
-  nsCString lockFileName;
+  nsAutoCString lockFileName;
 
   // The following is a small hack which will allow us to only load the library
   // which supports the netscape.cfg file if the preference is defined. We
   // test for the existence of the pref, set in the all.js (mozilla) or
   // all-ns.js (netscape 6), and if it exists we startup the pref config
   // category which will do the rest.
 
-  nsresult rv = PREF_CopyCharPref(
-    "general.config.filename", getter_Copies(lockFileName), false);
+  nsresult rv =
+    PREF_GetCStringPref("general.config.filename", lockFileName, false);
   if (NS_SUCCEEDED(rv)) {
     NS_CreateServicesFromCategory(
       "pref-config-startup",
       static_cast<nsISupports*>(static_cast<void*>(this)),
       "pref-config-startup");
   }
 
   nsCOMPtr<nsIObserverService> observerService =
@@ -4909,41 +4897,36 @@ Preferences::GetInt(const char* aPref, i
 }
 
 /* static */ nsresult
 Preferences::GetFloat(const char* aPref, float* aResult)
 {
   NS_PRECONDITION(aResult, "aResult must not be NULL");
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
   nsAutoCString result;
-  nsresult rv = PREF_CopyCharPref(aPref, getter_Copies(result), false);
+  nsresult rv = PREF_GetCStringPref(aPref, result, false);
   if (NS_SUCCEEDED(rv)) {
     *aResult = result.ToFloat(&rv);
   }
   return rv;
 }
 
 /* static */ nsresult
 Preferences::GetCString(const char* aPref, nsACString& aResult)
 {
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
-  char* result;
-  nsresult rv = PREF_CopyCharPref(aPref, &result, false);
-  if (NS_SUCCEEDED(rv)) {
-    aResult.Adopt(result);
-  }
-  return rv;
+  return PREF_GetCStringPref(aPref, aResult, false);
 }
 
 /* static */ nsresult
 Preferences::GetString(const char* aPref, nsAString& aResult)
 {
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
   nsAutoCString result;
-  nsresult rv = PREF_CopyCharPref(aPref, getter_Copies(result), false);
+  nsresult rv = PREF_GetCStringPref(aPref, result, false);
   if (NS_SUCCEEDED(rv)) {
     CopyUTF8toUTF16(result, aResult);
   }
   return rv;
 }
 
 /* static */ nsresult
 Preferences::GetLocalizedCString(const char* aPref, nsACString& aResult)
@@ -4977,41 +4960,41 @@ Preferences::GetComplex(const char* aPre
   return sRootBranch->GetComplexValue(aPref, aType, aResult);
 }
 
 /* static */ nsresult
 Preferences::SetCString(const char* aPref, const char* aValue)
 {
   ENSURE_MAIN_PROCESS_WITH_WARNING("SetCString", aPref);
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
-  return PREF_SetCharPref(aPref, aValue, false);
+  return PREF_SetCStringPref(aPref, nsDependentCString(aValue), false);
 }
 
 /* static */ nsresult
 Preferences::SetCString(const char* aPref, const nsACString& aValue)
 {
   ENSURE_MAIN_PROCESS_WITH_WARNING("SetCString", aPref);
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
-  return PREF_SetCharPref(aPref, PromiseFlatCString(aValue).get(), false);
+  return PREF_SetCStringPref(aPref, aValue, false);
 }
 
 /* static */ nsresult
 Preferences::SetString(const char* aPref, const char16ptr_t aValue)
 {
   ENSURE_MAIN_PROCESS_WITH_WARNING("SetString", aPref);
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
-  return PREF_SetCharPref(aPref, NS_ConvertUTF16toUTF8(aValue).get(), false);
+  return PREF_SetCStringPref(aPref, NS_ConvertUTF16toUTF8(aValue), false);
 }
 
 /* static */ nsresult
 Preferences::SetString(const char* aPref, const nsAString& aValue)
 {
   ENSURE_MAIN_PROCESS_WITH_WARNING("SetString", aPref);
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
-  return PREF_SetCharPref(aPref, NS_ConvertUTF16toUTF8(aValue).get(), false);
+  return PREF_SetCStringPref(aPref, NS_ConvertUTF16toUTF8(aValue), false);
 }
 
 /* static */ nsresult
 Preferences::SetBool(const char* aPref, bool aValue)
 {
   ENSURE_MAIN_PROCESS_WITH_WARNING("SetBool", aPref);
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
   return PREF_SetBoolPref(aPref, aValue, false);
@@ -5400,30 +5383,25 @@ Preferences::GetDefaultInt(const char* a
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
   return PREF_GetIntPref(aPref, aResult, true);
 }
 
 /* static */ nsresult
 Preferences::GetDefaultCString(const char* aPref, nsACString& aResult)
 {
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
-  char* result;
-  nsresult rv = PREF_CopyCharPref(aPref, &result, true);
-  if (NS_SUCCEEDED(rv)) {
-    aResult.Adopt(result);
-  }
-  return rv;
+  return PREF_GetCStringPref(aPref, aResult, true);
 }
 
 /* static */ nsresult
 Preferences::GetDefaultString(const char* aPref, nsAString& aResult)
 {
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
   nsAutoCString result;
-  nsresult rv = PREF_CopyCharPref(aPref, getter_Copies(result), true);
+  nsresult rv = PREF_GetCStringPref(aPref, result, true);
   if (NS_SUCCEEDED(rv)) {
     CopyUTF8toUTF16(result, aResult);
   }
   return rv;
 }
 
 /* static */ nsresult
 Preferences::GetDefaultLocalizedCString(const char* aPref, nsACString& aResult)
--- a/modules/libpref/nsIPrefBranch.idl
+++ b/modules/libpref/nsIPrefBranch.idl
@@ -36,17 +36,17 @@ interface nsIPrefBranch : nsISupports
   const long PREF_STRING = 32;
   const long PREF_INT = 64;
   const long PREF_BOOL = 128;
 
   /**
    * Called to get the root on which this branch is based, such as
    * "browser.startup."
    */
-  readonly attribute string root;
+  readonly attribute ACString root;
 
   /**
    * Called to determine the type of a specific preference.
    *
    * @param aPrefName The preference to get the type of.
    *
    * @return long     A value representing the type of the preference. This
    *                  value will be PREF_STRING, PREF_INT, or PREF_BOOL.
@@ -99,45 +99,46 @@ interface nsIPrefBranch : nsISupports
   float getFloatPrefXPCOM(in string aPrefName);
 
   /**
    * Called to get the state of an individual ascii string preference.
    *
    * @param aPrefName The string preference to retrieve.
    * @param aDefaultValue The string to return if the preference is not set.
    *
-   * @return string   The value of the requested string preference.
+   * @return ACString   The value of the requested string preference.
    *
    * @see setCharPref
    */
   [optional_argc,binaryname(GetCharPrefWithDefault)]
-  string getCharPref(in string aPrefName, [optional] in string aDefaultValue);
+  ACString getCharPref(in string aPrefName,
+                       [optional] in ACString aDefaultValue);
   [noscript,binaryname(GetCharPref)]
-  string getCharPrefXPCOM(in string aPrefName);
+  ACString getCharPrefXPCOM(in string aPrefName);
 
   /**
    * Called to set the state of an individual ascii string preference.
    *
    * @param aPrefName The string preference to set.
    * @param aValue    The string value to set the preference to.
    *
    * @throws Error if setting failed or the preference has a default
              value of a type other than string.
    *
    * @see getCharPref
    */
-  void setCharPref(in string aPrefName, in string aValue);
+  void setCharPref(in string aPrefName, in ACString aValue);
 
   /**
    * Called to get the state of an individual unicode string preference.
    *
    * @param aPrefName The string preference to retrieve.
    * @param aDefaultValue The string to return if the preference is not set.
    *
-   * @return string   The value of the requested string preference.
+   * @return ACString   The value of the requested string preference.
    *
    * @see setStringPref
    */
   [optional_argc]
   AUTF8String getStringPref(in string aPrefName,
                             [optional] in AUTF8String aDefaultValue);
 
   /**
--- a/netwerk/base/nsIOService.cpp
+++ b/netwerk/base/nsIOService.cpp
@@ -1359,20 +1359,20 @@ nsIOService::PrefsChanged(nsIPrefBranch 
             }
         }
     }
 }
 
 void
 nsIOService::ParsePortList(nsIPrefBranch *prefBranch, const char *pref, bool remove)
 {
-    nsCString portList;
+    nsAutoCString portList;
 
     // Get a pref string and chop it up into a list of ports.
-    prefBranch->GetCharPref(pref, getter_Copies(portList));
+    prefBranch->GetCharPref(pref, portList);
     if (!portList.IsVoid()) {
         nsTArray<nsCString> portListArray;
         ParseString(portList, ',', portListArray);
         uint32_t index;
         for (index=0; index < portListArray.Length(); index++) {
             portListArray[index].StripWhitespace();
             int32_t portBegin, portEnd;
 
--- a/netwerk/base/nsProtocolProxyService.cpp
+++ b/netwerk/base/nsProtocolProxyService.cpp
@@ -422,18 +422,18 @@ proxy_MaskIPv6Addr(PRIPv6Addr &addr, uin
     }
 }
 
 static void
 proxy_GetStringPref(nsIPrefBranch *aPrefBranch,
                     const char    *aPref,
                     nsCString     &aResult)
 {
-    nsCString temp;
-    nsresult rv = aPrefBranch->GetCharPref(aPref, getter_Copies(temp));
+    nsAutoCString temp;
+    nsresult rv = aPrefBranch->GetCharPref(aPref, temp);
     if (NS_FAILED(rv))
         aResult.Truncate();
     else {
         aResult.Assign(temp);
         // all of our string prefs are hostnames, so we should remove any
         // whitespace characters that the user might have unknowingly entered.
         aResult.StripWhitespace();
     }
@@ -555,19 +555,18 @@ nsProtocolProxyService::ReloadNetworkPAC
 
     int32_t type;
     nsresult rv = prefs->GetIntPref(PROXY_PREF("type"), &type);
     if (NS_FAILED(rv)) {
         return NS_OK;
     }
 
     if (type == PROXYCONFIG_PAC) {
-        nsCString pacSpec;
-        prefs->GetCharPref(PROXY_PREF("autoconfig_url"),
-                           getter_Copies(pacSpec));
+        nsAutoCString pacSpec;
+        prefs->GetCharPref(PROXY_PREF("autoconfig_url"), pacSpec);
         if (!pacSpec.IsEmpty()) {
             nsCOMPtr<nsIURI> pacURI;
             rv = NS_NewURI(getter_AddRefs(pacURI), pacSpec);
             if(!NS_SUCCEEDED(rv)) {
                 return rv;
             }
 
             nsProtocolInfo pac;
@@ -687,17 +686,17 @@ nsProtocolProxyService::Observe(nsISuppo
 }
 
 void
 nsProtocolProxyService::PrefsChanged(nsIPrefBranch *prefBranch,
                                      const char    *pref)
 {
     nsresult rv = NS_OK;
     bool reloadPAC = false;
-    nsCString tempString;
+    nsAutoCString tempString;
 
     if (!pref || !strcmp(pref, PROXY_PREF("type"))) {
         int32_t type = -1;
         rv = prefBranch->GetIntPref(PROXY_PREF("type"), &type);
         if (NS_SUCCEEDED(rv)) {
             // bug 115720 - for ns4.x backwards compatibility
             if (type == PROXYCONFIG_DIRECT4X) {
                 type = PROXYCONFIG_DIRECT;
@@ -771,18 +770,17 @@ nsProtocolProxyService::PrefsChanged(nsI
                           mProxyOverTLS);
     }
 
     if (!pref || !strcmp(pref, PROXY_PREF("failover_timeout")))
         proxy_GetIntPref(prefBranch, PROXY_PREF("failover_timeout"),
                          mFailedProxyTimeout);
 
     if (!pref || !strcmp(pref, PROXY_PREF("no_proxies_on"))) {
-        rv = prefBranch->GetCharPref(PROXY_PREF("no_proxies_on"),
-                                     getter_Copies(tempString));
+        rv = prefBranch->GetCharPref(PROXY_PREF("no_proxies_on"), tempString);
         if (NS_SUCCEEDED(rv))
             LoadHostFilters(tempString);
     }
 
     // We're done if not using something that could give us a PAC URL
     // (PAC, WPAD or System)
     if (mProxyConfig != PROXYCONFIG_PAC && mProxyConfig != PROXYCONFIG_WPAD &&
         mProxyConfig != PROXYCONFIG_SYSTEM)
@@ -793,18 +791,17 @@ nsProtocolProxyService::PrefsChanged(nsI
     //  2) network.proxy.autoconfig_url changed and PAC is configured
 
     if (!pref || !strcmp(pref, PROXY_PREF("autoconfig_url")))
         reloadPAC = true;
 
     if (reloadPAC) {
         tempString.Truncate();
         if (mProxyConfig == PROXYCONFIG_PAC) {
-            prefBranch->GetCharPref(PROXY_PREF("autoconfig_url"),
-                                    getter_Copies(tempString));
+            prefBranch->GetCharPref(PROXY_PREF("autoconfig_url"), tempString);
             if (mPACMan && !mPACMan->IsPACURI(tempString)) {
                 LOG(("PAC Thread URI Changed - Reset Pac Thread"));
                 ResetPACThread();
             }
         } else if (mProxyConfig == PROXYCONFIG_WPAD) {
             // We diverge from the WPAD spec here in that we don't walk the
             // hosts's FQDN, stripping components until we hit a TLD.  Doing so
             // is dangerous in the face of an incomplete list of TLDs, and TLDs
@@ -1241,19 +1238,19 @@ nsProtocolProxyService::ReloadPAC()
     if (!prefs)
         return NS_OK;
 
     int32_t type;
     nsresult rv = prefs->GetIntPref(PROXY_PREF("type"), &type);
     if (NS_FAILED(rv))
         return NS_OK;
 
-    nsCString pacSpec;
+    nsAutoCString pacSpec;
     if (type == PROXYCONFIG_PAC)
-        prefs->GetCharPref(PROXY_PREF("autoconfig_url"), getter_Copies(pacSpec));
+        prefs->GetCharPref(PROXY_PREF("autoconfig_url"), pacSpec);
     else if (type == PROXYCONFIG_WPAD)
         pacSpec.AssignLiteral(WPAD_URL);
     else if (type == PROXYCONFIG_SYSTEM) {
         if (mSystemProxySettings) {
             AsyncConfigureFromPAC(true, true);
         } else {
             ResetPACThread();
         }
--- a/netwerk/dns/nsDNSService2.cpp
+++ b/netwerk/dns/nsDNSService2.cpp
@@ -542,36 +542,36 @@ nsDNSService::Init()
     uint32_t defaultGracePeriod = 60; // seconds
     bool     disableIPv6      = false;
     bool     offlineLocalhost = true;
     bool     disablePrefetch  = false;
     bool     blockDotOnion    = true;
     int      proxyType        = nsIProtocolProxyService::PROXYCONFIG_DIRECT;
     bool     notifyResolution = false;
 
-    nsCString ipv4OnlyDomains;
-    nsCString localDomains;
-    nsCString forceResolve;
+    nsAutoCString ipv4OnlyDomains;
+    nsAutoCString localDomains;
+    nsAutoCString forceResolve;
 
     // read prefs
     nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
     if (prefs) {
         int32_t val;
         if (NS_SUCCEEDED(prefs->GetIntPref(kPrefDnsCacheEntries, &val)))
             maxCacheEntries = (uint32_t) val;
         if (NS_SUCCEEDED(prefs->GetIntPref(kPrefDnsCacheExpiration, &val)))
             defaultCacheLifetime = val;
         if (NS_SUCCEEDED(prefs->GetIntPref(kPrefDnsCacheGrace, &val)))
             defaultGracePeriod = val;
 
         // ASSUMPTION: pref branch does not modify out params on failure
         prefs->GetBoolPref(kPrefDisableIPv6, &disableIPv6);
-        prefs->GetCharPref(kPrefIPv4OnlyDomains, getter_Copies(ipv4OnlyDomains));
-        prefs->GetCharPref(kPrefDnsLocalDomains, getter_Copies(localDomains));
-        prefs->GetCharPref(kPrefDnsForceResolve, getter_Copies(forceResolve));
+        prefs->GetCharPref(kPrefIPv4OnlyDomains, ipv4OnlyDomains);
+        prefs->GetCharPref(kPrefDnsLocalDomains, localDomains);
+        prefs->GetCharPref(kPrefDnsForceResolve, forceResolve);
         prefs->GetBoolPref(kPrefDnsOfflineLocalhost, &offlineLocalhost);
         prefs->GetBoolPref(kPrefDisablePrefetch, &disablePrefetch);
         prefs->GetBoolPref(kPrefBlockDotOnion, &blockDotOnion);
 
         // If a manual proxy is in use, disable prefetch implicitly
         prefs->GetIntPref("network.proxy.type", &proxyType);
         prefs->GetBoolPref(kPrefDnsNotifyResolution, &notifyResolution);
 
--- a/netwerk/dns/nsIDNService.cpp
+++ b/netwerk/dns/nsIDNService.cpp
@@ -118,19 +118,19 @@ void nsIDNService::prefsChanged(nsIPrefB
   }
   if (!pref || NS_LITERAL_STRING(NS_NET_PREF_IDNUSEWHITELIST).Equals(pref)) {
     bool val;
     if (NS_SUCCEEDED(prefBranch->GetBoolPref(NS_NET_PREF_IDNUSEWHITELIST,
                                              &val)))
       mIDNUseWhitelist = val;
   }
   if (!pref || NS_LITERAL_STRING(NS_NET_PREF_IDNRESTRICTION).Equals(pref)) {
-    nsCString profile;
+    nsAutoCString profile;
     if (NS_FAILED(prefBranch->GetCharPref(NS_NET_PREF_IDNRESTRICTION,
-                                          getter_Copies(profile)))) {
+                                          profile))) {
       profile.Truncate();
     }
     if (profile.EqualsLiteral("moderate")) {
       mRestrictionProfile = eModeratelyRestrictiveProfile;
     } else if (profile.EqualsLiteral("high")) {
       mRestrictionProfile = eHighlyRestrictiveProfile;
     } else {
       mRestrictionProfile = eASCIIOnlyProfile;
--- a/netwerk/protocol/ftp/nsFtpConnectionThread.cpp
+++ b/netwerk/protocol/ftp/nsFtpConnectionThread.cpp
@@ -780,25 +780,25 @@ nsFtpState::S_pass() {
 
     mResponseMsg = "";
 
     if (mAnonymous) {
         if (!mPassword.IsEmpty()) {
             // XXX Is UTF-8 the best choice?
             AppendUTF16toUTF8(mPassword, passwordStr);
         } else {
-            nsCString anonPassword;
+            nsAutoCString anonPassword;
             bool useRealEmail = false;
             nsCOMPtr<nsIPrefBranch> prefs =
                     do_GetService(NS_PREFSERVICE_CONTRACTID);
             if (prefs) {
                 rv = prefs->GetBoolPref("advanced.mailftp", &useRealEmail);
                 if (NS_SUCCEEDED(rv) && useRealEmail) {
                     prefs->GetCharPref("network.ftp.anonymous_password",
-                                       getter_Copies(anonPassword));
+                                       anonPassword);
                 }
             }
             if (!anonPassword.IsEmpty()) {
                 passwordStr.AppendASCII(anonPassword.get());
             } else {
                 // We need to default to a valid email address - bug 101027
                 // example.com is reserved (rfc2606), so use that
                 passwordStr.AppendLiteral("mozilla@example.com");
--- a/netwerk/protocol/gio/nsGIOProtocolHandler.cpp
+++ b/netwerk/protocol/gio/nsGIOProtocolHandler.cpp
@@ -919,17 +919,17 @@ void
 nsGIOProtocolHandler::InitSupportedProtocolsPref(nsIPrefBranch *prefs)
 {
   // Get user preferences to determine which protocol is supported.
   // Gvfs/GIO has a set of supported protocols like obex, network, archive,
   // computer, dav, cdda, gphoto2, trash, etc. Some of these seems to be
   // irrelevant to process by browser. By default accept only smb and sftp
   // protocols so far.
   nsresult rv = prefs->GetCharPref(MOZ_GIO_SUPPORTED_PROTOCOLS,
-                                   getter_Copies(mSupportedProtocols));
+                                   mSupportedProtocols);
   if (NS_SUCCEEDED(rv)) {
     mSupportedProtocols.StripWhitespace();
     ToLowerCase(mSupportedProtocols);
   }
   else
     mSupportedProtocols.AssignLiteral("smb:,sftp:"); // use defaults
 
   LOG(("gio: supported protocols \"%s\"\n", mSupportedProtocols.get()));
--- a/netwerk/protocol/http/HttpAuthUtils.cpp
+++ b/netwerk/protocol/http/HttpAuthUtils.cpp
@@ -132,25 +132,21 @@ URIMatchesPrefPattern(nsIURI *uri, const
     return false;
   }
 
   port = NS_GetRealPort(uri);
   if (port == -1) {
     return false;
   }
 
-  char *hostList;
-  if (NS_FAILED(prefs->GetCharPref(pref, &hostList)) || !hostList) {
+  nsAutoCString hostList;
+  if (NS_FAILED(prefs->GetCharPref(pref, hostList)) || hostList.IsEmpty()) {
     return false;
   }
 
-  struct FreePolicy { void operator()(void* p) { free(p); } };
-  mozilla::UniquePtr<char[], FreePolicy> hostListScope;
-  hostListScope.reset(hostList);
-
   // pseudo-BNF
   // ----------
   //
   // url-list       base-url ( base-url "," LWS )*
   // base-url       ( scheme-part | host-part | scheme-part host-part )
   // scheme-part    scheme "://"
   // host-part      host [":" port]
   //
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -1160,18 +1160,17 @@ nsHttpHandler::PrefsChanged(nsIPrefBranc
     if (PREF_CHANGED(UA_PREF("compatMode.firefox"))) {
         rv = prefs->GetBoolPref(UA_PREF("compatMode.firefox"), &cVar);
         mCompatFirefoxEnabled = (NS_SUCCEEDED(rv) && cVar);
         mUserAgentIsDirty = true;
     }
 
     // general.useragent.override
     if (PREF_CHANGED(UA_PREF("override"))) {
-        prefs->GetCharPref(UA_PREF("override"),
-                            getter_Copies(mUserAgentOverride));
+        prefs->GetCharPref(UA_PREF("override"), mUserAgentOverride);
         mUserAgentIsDirty = true;
     }
 
 #ifdef ANDROID
     // general.useragent.use_device
     if (PREF_CHANGED(UA_PREF("use_device"))) {
         if (Preferences::GetBool(UA_PREF("use_device"), false)) {
             mDeviceModelId = mozilla::net::GetDeviceModelId();
@@ -1338,80 +1337,77 @@ nsHttpHandler::PrefsChanged(nsIPrefBranc
 
     if (PREF_CHANGED(HTTP_PREF("fast-fallback-to-IPv4"))) {
         rv = prefs->GetBoolPref(HTTP_PREF("fast-fallback-to-IPv4"), &cVar);
         if (NS_SUCCEEDED(rv))
             mFastFallbackToIPv4 = cVar;
     }
 
     if (PREF_CHANGED(HTTP_PREF("version"))) {
-        nsCString httpVersion;
-        prefs->GetCharPref(HTTP_PREF("version"), getter_Copies(httpVersion));
+        nsAutoCString httpVersion;
+        prefs->GetCharPref(HTTP_PREF("version"), httpVersion);
         if (!httpVersion.IsVoid()) {
             if (httpVersion.EqualsLiteral("1.1"))
                 mHttpVersion = NS_HTTP_VERSION_1_1;
             else if (httpVersion.EqualsLiteral("0.9"))
                 mHttpVersion = NS_HTTP_VERSION_0_9;
             else
                 mHttpVersion = NS_HTTP_VERSION_1_0;
         }
     }
 
     if (PREF_CHANGED(HTTP_PREF("proxy.version"))) {
-        nsCString httpVersion;
-        prefs->GetCharPref(HTTP_PREF("proxy.version"), getter_Copies(httpVersion));
+        nsAutoCString httpVersion;
+        prefs->GetCharPref(HTTP_PREF("proxy.version"), httpVersion);
         if (!httpVersion.IsVoid()) {
             if (httpVersion.EqualsLiteral("1.1"))
                 mProxyHttpVersion = NS_HTTP_VERSION_1_1;
             else
                 mProxyHttpVersion = NS_HTTP_VERSION_1_0;
             // it does not make sense to issue a HTTP/0.9 request to a proxy server
         }
     }
 
     if (PREF_CHANGED(HTTP_PREF("qos"))) {
         rv = prefs->GetIntPref(HTTP_PREF("qos"), &val);
         if (NS_SUCCEEDED(rv))
             mQoSBits = (uint8_t) clamped(val, 0, 0xff);
     }
 
     if (PREF_CHANGED(HTTP_PREF("accept.default"))) {
-        nsCString accept;
-        rv = prefs->GetCharPref(HTTP_PREF("accept.default"),
-                                  getter_Copies(accept));
+        nsAutoCString accept;
+        rv = prefs->GetCharPref(HTTP_PREF("accept.default"), accept);
         if (NS_SUCCEEDED(rv)) {
             rv = SetAccept(accept.get());
             MOZ_ASSERT(NS_SUCCEEDED(rv));
         }
     }
 
     if (PREF_CHANGED(HTTP_PREF("accept-encoding"))) {
-        nsCString acceptEncodings;
-        rv = prefs->GetCharPref(HTTP_PREF("accept-encoding"),
-                                  getter_Copies(acceptEncodings));
+        nsAutoCString acceptEncodings;
+        rv = prefs->GetCharPref(HTTP_PREF("accept-encoding"), acceptEncodings);
         if (NS_SUCCEEDED(rv)) {
             rv = SetAcceptEncodings(acceptEncodings.get(), false);
             MOZ_ASSERT(NS_SUCCEEDED(rv));
         }
     }
 
     if (PREF_CHANGED(HTTP_PREF("accept-encoding.secure"))) {
-        nsCString acceptEncodings;
+        nsAutoCString acceptEncodings;
         rv = prefs->GetCharPref(HTTP_PREF("accept-encoding.secure"),
-                                  getter_Copies(acceptEncodings));
+                                acceptEncodings);
         if (NS_SUCCEEDED(rv)) {
             rv = SetAcceptEncodings(acceptEncodings.get(), true);
             MOZ_ASSERT(NS_SUCCEEDED(rv));
         }
     }
 
     if (PREF_CHANGED(HTTP_PREF("default-socket-type"))) {
-        nsCString sval;
-        rv = prefs->GetCharPref(HTTP_PREF("default-socket-type"),
-                                getter_Copies(sval));
+        nsAutoCString sval;
+        rv = prefs->GetCharPref(HTTP_PREF("default-socket-type"), sval);
         if (NS_SUCCEEDED(rv)) {
             if (sval.IsEmpty())
                 mDefaultSocketType.SetIsVoid(true);
             else {
                 // verify that this socket type is actually valid
                 nsCOMPtr<nsISocketProviderService> sps(
                         do_GetService(NS_SOCKETPROVIDERSERVICE_CONTRACTID));
                 if (sps) {
--- a/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
+++ b/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
@@ -144,19 +144,19 @@ nsTypeAheadFind::PrefsReset()
   NS_ENSURE_TRUE(prefBranch, NS_ERROR_FAILURE);
 
   prefBranch->GetBoolPref("accessibility.typeaheadfind.startlinksonly",
                           &mStartLinksOnlyPref);
 
   bool isSoundEnabled = true;
   prefBranch->GetBoolPref("accessibility.typeaheadfind.enablesound",
                            &isSoundEnabled);
-  nsCString soundStr;
+  nsAutoCString soundStr;
   if (isSoundEnabled)
-    prefBranch->GetCharPref("accessibility.typeaheadfind.soundURL", getter_Copies(soundStr));
+    prefBranch->GetCharPref("accessibility.typeaheadfind.soundURL", soundStr);
 
   mNotFoundSoundURL = soundStr;
 
   if (!mNotFoundSoundURL.IsEmpty() && !mNotFoundSoundURL.EqualsLiteral("beep")) {
     if (!mSoundInterface) {
       mSoundInterface = do_CreateInstance("@mozilla.org/sound;1");
     }
 
--- a/toolkit/components/url-classifier/nsUrlClassifierUtils.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierUtils.cpp
@@ -131,19 +131,18 @@ InitListUpdateRequest(ThreatType aThreat
 static ClientInfo*
 CreateClientInfo()
 {
   ClientInfo* c = new ClientInfo();
 
   nsCOMPtr<nsIPrefBranch> prefBranch =
     do_GetService(NS_PREFSERVICE_CONTRACTID);
 
-  nsCString clientId;
-  nsresult rv = prefBranch->GetCharPref("browser.safebrowsing.id",
-                                        getter_Copies(clientId));
+  nsAutoCString clientId;
+  nsresult rv = prefBranch->GetCharPref("browser.safebrowsing.id", clientId);
 
   if (NS_FAILED(rv)) {
     clientId = "Firefox"; // Use "Firefox" as fallback.
   }
 
   c->set_client_id(clientId.get());
 
   return c;
@@ -339,18 +338,18 @@ nsUrlClassifierUtils::GetTelemetryProvid
 NS_IMETHODIMP
 nsUrlClassifierUtils::GetProtocolVersion(const nsACString& aProvider,
                                          nsACString& aVersion)
 {
   nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID);
   if (prefBranch) {
       nsPrintfCString prefName("browser.safebrowsing.provider.%s.pver",
                                nsCString(aProvider).get());
-      nsCString version;
-      nsresult rv = prefBranch->GetCharPref(prefName.get(), getter_Copies(version));
+      nsAutoCString version;
+      nsresult rv = prefBranch->GetCharPref(prefName.get(), version);
 
       aVersion = NS_SUCCEEDED(rv) ? version.get() : DEFAULT_PROTOCOL_VERSION;
   } else {
       aVersion = DEFAULT_PROTOCOL_VERSION;
   }
 
   return NS_OK;
 }
@@ -831,19 +830,18 @@ nsUrlClassifierUtils::ReadProvidersFromP
   // Now we have all providers. Check which one owns |aTableName|.
   // e.g. The owning lists of provider "google" is defined in
   // "browser.safebrowsing.provider.google.lists".
   for (auto itr = providers.Iter(); !itr.Done(); itr.Next()) {
     auto entry = itr.Get();
     nsCString provider(entry->GetKey());
     nsPrintfCString owninListsPref("%s.lists", provider.get());
 
-    nsCString owningLists;
-    nsresult rv = prefBranch->GetCharPref(owninListsPref.get(),
-                                          getter_Copies(owningLists));
+    nsAutoCString owningLists;
+    nsresult rv = prefBranch->GetCharPref(owninListsPref.get(), owningLists);
     if (NS_FAILED(rv)) {
       continue;
     }
 
     // We've got the owning lists (represented as string) of |provider|.
     // Build the dictionary for the owning list and the current provider.
     nsTArray<nsCString> tables;
     Classifier::SplitTables(owningLists, tables);
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -4354,18 +4354,18 @@ XREMain::XRE_mainRun()
 #ifdef MOZ_CRASHREPORTER
   // tell the crash reporter to also send the release channel
   nsCOMPtr<nsIPrefService> prefs = do_GetService("@mozilla.org/preferences-service;1", &rv);
   if (NS_SUCCEEDED(rv)) {
     nsCOMPtr<nsIPrefBranch> defaultPrefBranch;
     rv = prefs->GetDefaultBranch(nullptr, getter_AddRefs(defaultPrefBranch));
 
     if (NS_SUCCEEDED(rv)) {
-      nsCString sval;
-      rv = defaultPrefBranch->GetCharPref("app.update.channel", getter_Copies(sval));
+      nsAutoCString sval;
+      rv = defaultPrefBranch->GetCharPref("app.update.channel", sval);
       if (NS_SUCCEEDED(rv)) {
         CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("ReleaseChannel"),
                                             sval);
       }
     }
   }
   // Needs to be set after xpcom initialization.
   CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("FramePoisonBase"),