Bug 1384835 (part 3) - Remove the Preferences::Get*CString() variants that return nsAdoptingCString. r=froydnj.
☠☠ backed out by 88e14ba4308e ☠ ☠
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 27 Jul 2017 16:45:10 +1000
changeset 420307 ef5feef07bed07583c52e434dbc5e4b9a2545deb
parent 420306 5df4d877860281f66dc14b512de963539dc443b0
child 420308 dc186bad8bd537919a15722a1a79dd46660f95f1
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1384835
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1384835 (part 3) - Remove the Preferences::Get*CString() variants that return nsAdoptingCString. r=froydnj. This is similar like the previous patch, but for the 8-bit string variants. Also, it changes assignment to Adopt() in GetCString() and GetDefaultCString() to avoid an extra copy.
caps/nsScriptSecurityManager.cpp
chrome/nsChromeRegistryChrome.cpp
docshell/base/nsDefaultURIFixup.cpp
docshell/base/nsDocShell.cpp
dom/audiochannel/AudioChannelAgent.cpp
dom/base/nsGlobalWindow.cpp
dom/base/nsObjectLoadingContent.cpp
dom/base/nsPluginArray.cpp
dom/encoding/FallbackEncoding.cpp
dom/events/Event.cpp
dom/indexedDB/IndexedDatabaseManager.cpp
dom/ipc/ContentChild.cpp
dom/ipc/ContentParent.cpp
dom/media/DecoderDoctorDiagnostics.cpp
dom/media/MediaManager.cpp
dom/media/webspeech/recognition/SpeechRecognition.cpp
dom/plugins/base/nsPluginHost.cpp
dom/presentation/provider/MulticastDNSDeviceProvider.cpp
dom/security/nsContentSecurityManager.cpp
editor/libeditor/HTMLEditRules.cpp
extensions/cookie/nsPermissionManager.cpp
gfx/gl/GLLibraryEGL.cpp
gfx/thebes/gfxDWriteFontList.cpp
gfx/thebes/gfxFcPlatformFontList.cpp
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPlatformFontList.cpp
gfx/vr/gfxVROSVR.cpp
image/imgLoader.cpp
intl/hyphenation/glue/nsHyphenationManager.cpp
intl/locale/android/OSPreferences_android.cpp
js/ipc/JavaScriptParent.cpp
layout/base/StaticPresData.cpp
layout/base/nsPresContext.cpp
modules/libpref/Preferences.cpp
modules/libpref/Preferences.h
netwerk/base/nsChannelClassifier.cpp
netwerk/protocol/http/nsHttpHandler.cpp
parser/html/nsHtml5StreamParser.cpp
security/apps/AppTrustDomain.cpp
security/sandbox/linux/broker/SandboxBrokerPolicyFactory.cpp
security/sandbox/linux/broker/SandboxBrokerPolicyFactory.h
uriloader/exthandler/nsExternalHelperAppService.cpp
widget/GfxInfoBase.cpp
widget/android/nsWindow.cpp
widget/gtk/nsLookAndFeel.cpp
widget/gtk/nsPSPrinters.cpp
xpcom/threads/BackgroundHangMonitor.cpp
xpfe/appshell/nsAppShellService.cpp
xpfe/appshell/nsXULWindow.cpp
--- a/caps/nsScriptSecurityManager.cpp
+++ b/caps/nsScriptSecurityManager.cpp
@@ -1637,17 +1637,18 @@ nsScriptSecurityManager::EnsureFileURIWh
 
     //
     // Rebuild the set of principals for which we allow file:// URI loads. This
     // implements a small subset of an old pref-based CAPS people that people
     // have come to depend on. See bug 995943.
     //
 
     mFileURIWhitelist.emplace();
-    auto policies = mozilla::Preferences::GetCString("capability.policy.policynames");
+    nsAutoCString policies;
+    mozilla::Preferences::GetCString("capability.policy.policynames", policies);
     for (uint32_t base = SkipPast<IsWhitespaceOrComma>(policies, 0), bound = 0;
          base < policies.Length();
          base = SkipPast<IsWhitespaceOrComma>(policies, bound))
     {
         // Grab the current policy name.
         bound = SkipUntil<IsWhitespaceOrComma>(policies, base);
         auto policyName = Substring(policies, base, bound - base);
 
@@ -1660,14 +1661,15 @@ nsScriptSecurityManager::EnsureFileURIWh
         if (NS_FAILED(rv) || !value.LowerCaseEqualsLiteral("allaccess")) {
             continue;
         }
 
         // Grab the list of domains associated with this policy.
         nsCString domainPrefName = NS_LITERAL_CSTRING("capability.policy.") +
                                    policyName +
                                    NS_LITERAL_CSTRING(".sites");
-        auto siteList = Preferences::GetCString(domainPrefName.get());
+        nsAutoCString siteList;
+        Preferences::GetCString(domainPrefName.get(), siteList);
         AddSitesToFileURIWhitelist(siteList);
     }
 
     return mFileURIWhitelist.ref();
 }
--- a/chrome/nsChromeRegistryChrome.cpp
+++ b/chrome/nsChromeRegistryChrome.cpp
@@ -246,21 +246,22 @@ nsChromeRegistryChrome::GetSelectedLocal
   return NS_OK;
 }
 
 nsresult
 nsChromeRegistryChrome::OverrideLocalePackage(const nsACString& aPackage,
                                               nsACString& aOverride)
 {
   const nsACString& pref = NS_LITERAL_CSTRING(PACKAGE_OVERRIDE_BRANCH) + aPackage;
-  nsAdoptingCString override = mozilla::Preferences::GetCString(PromiseFlatCString(pref).get());
-  if (override) {
+  nsAutoCString override;
+  nsresult rv =
+    mozilla::Preferences::GetCString(PromiseFlatCString(pref).get(), override);
+  if (NS_SUCCEEDED(rv)) {
     aOverride = override;
-  }
-  else {
+  } else {
     aOverride = aPackage;
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsChromeRegistryChrome::Observe(nsISupports *aSubject, const char *aTopic,
                                 const char16_t *someData)
--- a/docshell/base/nsDefaultURIFixup.cpp
+++ b/docshell/base/nsDefaultURIFixup.cpp
@@ -573,26 +573,27 @@ nsDefaultURIFixup::MakeAlternateURI(nsIU
     }
     ++iter;
   }
 
   // Get the prefix and suffix to stick onto the new hostname. By default these
   // are www. & .com but they could be any other value, e.g. www. & .org
 
   nsAutoCString prefix("www.");
-  nsAdoptingCString prefPrefix =
-    Preferences::GetCString("browser.fixup.alternate.prefix");
-  if (prefPrefix) {
+  nsAutoCString prefPrefix;
+  nsresult rv =
+    Preferences::GetCString("browser.fixup.alternate.prefix", prefPrefix);
+  if (NS_SUCCEEDED(rv)) {
     prefix.Assign(prefPrefix);
   }
 
   nsAutoCString suffix(".com");
-  nsAdoptingCString prefSuffix =
-    Preferences::GetCString("browser.fixup.alternate.suffix");
-  if (prefSuffix) {
+  nsAutoCString prefSuffix;
+  rv = Preferences::GetCString("browser.fixup.alternate.suffix", prefSuffix);
+  if (NS_SUCCEEDED(rv)) {
     suffix.Assign(prefSuffix);
   }
 
   if (numDots == 0) {
     newHost.Assign(prefix);
     newHost.Append(oldHost);
     newHost.Append(suffix);
   } else if (numDots == 1) {
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -5094,19 +5094,21 @@ nsDocShell::DisplayLoadError(nsresult aE
           // measuring STS separately allows us to measure click through
           // rates easily
           bucketId = nsISecurityUITelemetry::WARNING_BAD_CERT_TOP_STS;
         } else {
           bucketId = nsISecurityUITelemetry::WARNING_BAD_CERT_TOP;
         }
 
         // See if an alternate cert error page is registered
-        nsAdoptingCString alternateErrorPage =
-          Preferences::GetCString("security.alternate_certificate_error_page");
-        if (alternateErrorPage) {
+        nsAutoCString alternateErrorPage;
+        nsresult rv =
+          Preferences::GetCString("security.alternate_certificate_error_page",
+                                  alternateErrorPage);
+        if (NS_SUCCEEDED(rv)) {
           errorPage.Assign(alternateErrorPage);
         }
 
         if (!IsFrame() && errorPage.EqualsIgnoreCase("certerror")) {
           Telemetry::Accumulate(mozilla::Telemetry::SECURITY_UI, bucketId);
         }
 
       } else {
@@ -5118,19 +5120,20 @@ nsDocShell::DisplayLoadError(nsresult aE
              NS_ERROR_UNWANTED_URI == aError) {
     nsAutoCString host;
     aURI->GetHost(host);
     CopyUTF8toUTF16(host, formatStrs[0]);
     formatStrCount = 1;
 
     // Malware and phishing detectors may want to use an alternate error
     // page, but if the pref's not set, we'll fall back on the standard page
-    nsAdoptingCString alternateErrorPage =
-      Preferences::GetCString("urlclassifier.alternate_error_page");
-    if (alternateErrorPage) {
+    nsAutoCString alternateErrorPage;
+    nsresult rv = Preferences::GetCString("urlclassifier.alternate_error_page",
+                                          alternateErrorPage);
+    if (NS_SUCCEEDED(rv)) {
       errorPage.Assign(alternateErrorPage);
     }
 
     uint32_t bucketId;
     bool sendTelemetry = false;
     if (NS_ERROR_PHISHING_URI == aError) {
       sendTelemetry = true;
       error = "deceptiveBlocked";
--- a/dom/audiochannel/AudioChannelAgent.cpp
+++ b/dom/audiochannel/AudioChannelAgent.cpp
@@ -113,19 +113,20 @@ AudioChannelAgent::FindCorrectWindow(nsP
   if (!doc) {
     return NS_OK;
   }
 
   if (nsContentUtils::IsChromeDoc(doc)) {
     return NS_OK;
   }
 
-  nsAdoptingCString systemAppUrl =
-    mozilla::Preferences::GetCString("b2g.system_startup_url");
-  if (!systemAppUrl) {
+  nsAutoCString systemAppUrl;
+  nsresult rv =
+    mozilla::Preferences::GetCString("b2g.system_startup_url", systemAppUrl);
+  if (NS_FAILED(rv)) {
     return NS_OK;
   }
 
   nsCOMPtr<nsIPrincipal> principal = doc->NodePrincipal();
   nsCOMPtr<nsIURI> uri;
   principal->GetURI(getter_AddRefs(uri));
 
   if (uri) {
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -1700,22 +1700,21 @@ nsGlobalWindow::nsGlobalWindow(nsGlobalW
 
     Preferences::AddUintVarCache(&gThrottledIdlePeriodLength,
                                  "dom.idle_period.throttled_length",
                                  DEFAULT_THROTTLED_IDLE_PERIOD_LENGTH);
     sFirstTime = false;
   }
 
   if (gDumpFile == nullptr) {
-    const nsAdoptingCString& fname =
-      Preferences::GetCString("browser.dom.window.dump.file");
+    nsAutoCString fname;
+    Preferences::GetCString("browser.dom.window.dump.file", fname);
     if (!fname.IsEmpty()) {
-      // if this fails to open, Dump() knows to just go to stdout
-      // on null.
-      gDumpFile = fopen(fname, "wb+");
+      // If this fails to open, Dump() knows to just go to stdout on null.
+      gDumpFile = fopen(fname.get(), "wb+");
     } else {
       gDumpFile = stdout;
     }
   }
 
   mSerial = ++gSerialCounter;
 
 #ifdef DEBUG
@@ -6936,17 +6935,18 @@ struct FullscreenTransitionDuration
 
 static void
 GetFullscreenTransitionDuration(bool aEnterFullscreen,
                                 FullscreenTransitionDuration* aDuration)
 {
   const char* pref = aEnterFullscreen ?
     "full-screen-api.transition-duration.enter" :
     "full-screen-api.transition-duration.leave";
-  nsAdoptingCString prefValue = Preferences::GetCString(pref);
+  nsAutoCString prefValue;
+  Preferences::GetCString(pref, prefValue);
   if (!prefValue.IsEmpty()) {
     sscanf(prefValue.get(), "%hu%hu",
            &aDuration->mFadeIn, &aDuration->mFadeOut);
   }
 }
 
 class FullscreenTransitionTask : public Runnable
 {
--- a/dom/base/nsObjectLoadingContent.cpp
+++ b/dom/base/nsObjectLoadingContent.cpp
@@ -955,17 +955,18 @@ nsObjectLoadingContent::BuildParametersA
   bool isJava = IsJavaMIME(mContentType);
 
   nsCString codebase;
   if (isJava) {
       nsresult rv = mBaseURI->GetSpec(codebase);
       NS_ENSURE_SUCCESS(rv, rv);
   }
 
-  nsAdoptingCString wmodeOverride = Preferences::GetCString("plugins.force.wmode");
+  nsAutoCString wmodeOverride;
+  Preferences::GetCString("plugins.force.wmode", wmodeOverride);
   for (uint32_t i = 0; i < mCachedAttributes.Length(); i++) {
     if (!wmodeOverride.IsEmpty() && mCachedAttributes[i].mName.EqualsIgnoreCase("wmode")) {
       CopyASCIItoUTF16(wmodeOverride, mCachedAttributes[i].mValue);
       wmodeOverride.Truncate();
     } else if (!codebase.IsEmpty() && mCachedAttributes[i].mName.EqualsIgnoreCase("codebase")) {
       CopyASCIItoUTF16(codebase, mCachedAttributes[i].mValue);
       codebase.Truncate();
     }
@@ -1658,18 +1659,17 @@ nsObjectLoadingContent::UpdateObjectPara
   // that far.
   nsObjectLoadingContent::ParameterUpdateFlags retval = eParamNoChange;
 
   ///
   /// Initial MIME Type
   ///
 
   if (aJavaURI || thisContent->NodeInfo()->Equals(nsGkAtoms::applet)) {
-    nsAdoptingCString javaMIME = Preferences::GetCString(kPrefJavaMIME);
-    newMime = javaMIME;
+    Preferences::GetCString(kPrefJavaMIME, newMime);
     NS_ASSERTION(IsJavaMIME(newMime),
                  "plugin.mime.java should be recognized as java");
     isJava = true;
   } else {
     nsAutoString rawTypeAttr;
     thisContent->GetAttr(kNameSpaceID_None, nsGkAtoms::type, rawTypeAttr);
     if (!rawTypeAttr.IsEmpty()) {
       typeAttr = rawTypeAttr;
@@ -1682,17 +1682,18 @@ nsObjectLoadingContent::UpdateObjectPara
   /// classID
   ///
 
   if (caps & eSupportClassID) {
     nsAutoString classIDAttr;
     thisContent->GetAttr(kNameSpaceID_None, nsGkAtoms::classid, classIDAttr);
     if (!classIDAttr.IsEmpty()) {
       // Our classid support is limited to 'java:' ids
-      nsAdoptingCString javaMIME = Preferences::GetCString(kPrefJavaMIME);
+      nsAutoCString javaMIME;
+      Preferences::GetCString(kPrefJavaMIME, javaMIME);
       NS_ASSERTION(IsJavaMIME(javaMIME),
                    "plugin.mime.java should be recognized as java");
       RefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
       if (StringBeginsWith(classIDAttr, NS_LITERAL_STRING("java:")) &&
           pluginHost &&
           pluginHost->HavePluginForType(javaMIME)) {
         newMime = javaMIME;
         isJava = true;
--- a/dom/base/nsPluginArray.cpp
+++ b/dom/base/nsPluginArray.cpp
@@ -328,17 +328,19 @@ operator<(const RefPtr<nsPluginElement>&
 {
   // Sort plugins alphabetically by name.
   return lhs->PluginTag()->Name() < rhs->PluginTag()->Name();
 }
 
 static bool
 PluginShouldBeHidden(const nsCString& aName) {
   // This only supports one hidden plugin
-  return Preferences::GetCString("plugins.navigator.hidden_ctp_plugin").Equals(aName);
+  nsAutoCString value;
+  Preferences::GetCString("plugins.navigator.hidden_ctp_plugin", value);
+  return value.Equals(aName);
 }
 
 void
 nsPluginArray::EnsurePlugins()
 {
   if (!mPlugins.IsEmpty() || !mCTPPlugins.IsEmpty()) {
     // We already have an array of plugin elements.
     return;
--- a/dom/encoding/FallbackEncoding.cpp
+++ b/dom/encoding/FallbackEncoding.cpp
@@ -44,18 +44,18 @@ FallbackEncoding::FallbackEncoding()
 
 NotNull<const Encoding*>
 FallbackEncoding::Get()
 {
   if (mFallback) {
     return WrapNotNull(mFallback);
   }
 
-  const nsAdoptingCString& override =
-    Preferences::GetCString("intl.charset.fallback.override");
+  nsAutoCString override;
+  Preferences::GetCString("intl.charset.fallback.override", override);
   // Don't let the user break things by setting the override to unreasonable
   // values via about:config
   auto encoding = Encoding::ForLabel(override);
   if (!encoding || !encoding->IsAsciiCompatible() ||
       encoding == UTF_8_ENCODING) {
     mFallback = nullptr;
   } else {
     mFallback = encoding;
--- a/dom/events/Event.cpp
+++ b/dom/events/Event.cpp
@@ -895,17 +895,18 @@ Event::GetEventPopupControlState(WidgetE
 // static
 void
 Event::PopupAllowedEventsChanged()
 {
   if (sPopupAllowedEvents) {
     free(sPopupAllowedEvents);
   }
 
-  nsAdoptingCString str = Preferences::GetCString("dom.popup_allowed_events");
+  nsAutoCString str;
+  Preferences::GetCString("dom.popup_allowed_events", str);
 
   // We'll want to do this even if str is empty to avoid looking up
   // this pref all the time if it's not set.
   sPopupAllowedEvents = ToNewCString(str);
 }
 
 // static
 void
--- a/dom/indexedDB/IndexedDatabaseManager.cpp
+++ b/dom/indexedDB/IndexedDatabaseManager.cpp
@@ -426,18 +426,18 @@ IndexedDatabaseManager::Init()
 
   Preferences::RegisterCallbackAndCall(DataThresholdPrefChangedCallback,
                                        kDataThresholdPref);
 
   Preferences::RegisterCallbackAndCall(MaxSerializedMsgSizePrefChangeCallback,
                                        kPrefMaxSerilizedMsgSize);
 
 #ifdef ENABLE_INTL_API
-  const nsAdoptingCString& acceptLang =
-    Preferences::GetLocalizedCString("intl.accept_languages");
+  nsAutoCString acceptLang;
+  Preferences::GetLocalizedCString("intl.accept_languages", acceptLang);
 
   // Split values on commas.
   nsCCharSeparatedTokenizer langTokenizer(acceptLang, ',');
   while (langTokenizer.hasMoreTokens()) {
     nsAutoCString lang(langTokenizer.nextToken());
     icu::Locale locale = icu::Locale::createCanonical(lang.get());
     if (!locale.isBogus()) {
       // icu::Locale::getBaseName is always ASCII as per BCP 47
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -1512,23 +1512,25 @@ StartMacOSContentSandbox()
   info.appPath.assign(appPath.get());
   info.appBinaryPath.assign(appBinaryPath.get());
   info.appDir.assign(appDir.get());
   info.appTempDir.assign(tempDirPath.get());
 
   // These paths are used to whitelist certain directories used by the testing
   // system. They should not be considered a public API, and are only intended
   // for use in automation.
-  nsAdoptingCString testingReadPath1 =
-    Preferences::GetCString("security.sandbox.content.mac.testing_read_path1");
+  nsAutoCString testingReadPath1;
+  Preferences::GetCString("security.sandbox.content.mac.testing_read_path1",
+                          testingReadPath1);
   if (!testingReadPath1.IsEmpty()) {
     info.testingReadPath1.assign(testingReadPath1.get());
   }
-  nsAdoptingCString testingReadPath2 =
-    Preferences::GetCString("security.sandbox.content.mac.testing_read_path2");
+  nsAutoCString testingReadPath2;
+  Preferences::GetCString("security.sandbox.content.mac.testing_read_path2",
+                          testingReadPath2);
   if (!testingReadPath2.IsEmpty()) {
     info.testingReadPath2.assign(testingReadPath2.get());
   }
 
   if (mozilla::IsDevelopmentBuild()) {
     nsCOMPtr<nsIFile> repoDir;
     rv = mozilla::GetRepoDir(getter_AddRefs(repoDir));
     if (NS_FAILED(rv)) {
@@ -1606,21 +1608,22 @@ ContentChild::RecvSetProcessSandbox(cons
       brokerFd = fd.release();
       // brokerFd < 0 means to allow direct filesystem access, so
       // make absolutely sure that doesn't happen if the parent
       // didn't intend it.
       MOZ_RELEASE_ASSERT(brokerFd >= 0);
     }
     // Allow user overrides of seccomp-bpf syscall filtering
     std::vector<int> syscallWhitelist;
-    nsAdoptingCString extraSyscalls =
-      Preferences::GetCString("security.sandbox.content.syscall_whitelist");
-    if (extraSyscalls) {
+    nsAutoCString extraSyscalls;
+    nsresult rv =
+      Preferences::GetCString("security.sandbox.content.syscall_whitelist",
+                              extraSyscalls);
+    if (NS_SUCCEEDED(rv)) {
       for (const nsACString& callNrString : extraSyscalls.Split(',')) {
-        nsresult rv;
         int callNr = PromiseFlatCString(callNrString).ToInteger(&rv);
         if (NS_SUCCEEDED(rv)) {
           syscallWhitelist.push_back(callNr);
         }
       }
     }
     ContentChild* cc = ContentChild::GetSingleton();
     bool isFileProcess = cc->GetRemoteType().EqualsLiteral(FILE_REMOTE_TYPE);
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -2035,17 +2035,18 @@ ContentParent::LaunchSubprocess(ProcessP
     switch (Preferences::GetType(ContentPrefs::GetContentPref(i))) {
     case nsIPrefBranch::PREF_INT:
       intPrefs.Append(nsPrintfCString("%u:%d|", i, Preferences::GetInt(ContentPrefs::GetContentPref(i))));
       break;
     case nsIPrefBranch::PREF_BOOL:
       boolPrefs.Append(nsPrintfCString("%u:%d|", i, Preferences::GetBool(ContentPrefs::GetContentPref(i))));
       break;
     case nsIPrefBranch::PREF_STRING: {
-      nsAdoptingCString value(Preferences::GetCString(ContentPrefs::GetContentPref(i)));
+      nsAutoCString value;
+      Preferences::GetCString(ContentPrefs::GetContentPref(i), value);
       stringPrefs.Append(nsPrintfCString("%u:%d;%s|", i, value.Length(), value.get()));
 
     }
       break;
     case nsIPrefBranch::PREF_INVALID:
       break;
     default:
       printf("preference type: %x\n", Preferences::GetType(ContentPrefs::GetContentPref(i)));
--- a/dom/media/DecoderDoctorDiagnostics.cpp
+++ b/dom/media/DecoderDoctorDiagnostics.cpp
@@ -399,18 +399,18 @@ static bool
 AllowNotification(const NotificationAndReportStringId& aNotification)
 {
   // "media.decoder-doctor.notifications-allowed" controls which notifications
   // may be dispatched to the front-end. It either contains:
   // - '*' -> Allow everything.
   // - Comma-separater list of ids -> Allow if aReportStringId (from
   //                                  dom.properties) is one of them.
   // - Nothing (missing or empty) -> Disable everything.
-  nsAdoptingCString filter =
-    Preferences::GetCString("media.decoder-doctor.notifications-allowed");
+  nsAutoCString filter;
+  Preferences::GetCString("media.decoder-doctor.notifications-allowed", filter);
   return filter.EqualsLiteral("*") ||
          StringListContains(filter, aNotification.mReportStringId);
 }
 
 static bool
 AllowDecodeIssue(const MediaResult& aDecodeIssue, bool aDecodeIssueIsError)
 {
   if (aDecodeIssue == NS_OK) {
@@ -419,20 +419,21 @@ AllowDecodeIssue(const MediaResult& aDec
     return true;
   }
 
   // "media.decoder-doctor.decode-{errors,warnings}-allowed" controls which
   // decode issues may be dispatched to the front-end. It either contains:
   // - '*' -> Allow everything.
   // - Comma-separater list of ids -> Allow if the issue name is one of them.
   // - Nothing (missing or empty) -> Disable everything.
-  nsAdoptingCString filter =
-    Preferences::GetCString(aDecodeIssueIsError
-                            ? "media.decoder-doctor.decode-errors-allowed"
-                            : "media.decoder-doctor.decode-warnings-allowed");
+  nsAutoCString filter;
+  Preferences::GetCString(aDecodeIssueIsError
+                          ? "media.decoder-doctor.decode-errors-allowed"
+                          : "media.decoder-doctor.decode-warnings-allowed",
+                          filter);
   if (filter.EqualsLiteral("*")) {
     return true;
   }
 
   nsCString decodeIssueName;
   GetErrorName(aDecodeIssue.Code(), static_cast<nsACString&>(decodeIssueName));
   return StringListContains(filter, decodeIssueName);
 }
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -1694,26 +1694,26 @@ MediaManager::EnumerateRawDevices(uint64
                                   bool aFake)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aVideoType != MediaSourceEnum::Other ||
              aAudioType != MediaSourceEnum::Other);
   RefPtr<PledgeSourceSet> p = new PledgeSourceSet();
   uint32_t id = mOutstandingPledges.Append(*p);
 
-  nsAdoptingCString audioLoopDev, videoLoopDev;
+  nsAutoCString audioLoopDev, videoLoopDev;
   if (!aFake) {
     // Fake stream not requested. The entire device stack is available.
     // Loop in loopback devices if they are set, and their respective type is
     // requested. This is currently used for automated media tests only.
     if (aVideoType == MediaSourceEnum::Camera) {
-      videoLoopDev = Preferences::GetCString("media.video_loopback_dev");
+      Preferences::GetCString("media.video_loopback_dev", videoLoopDev);
     }
     if (aAudioType == MediaSourceEnum::Microphone) {
-      audioLoopDev = Preferences::GetCString("media.audio_loopback_dev");
+      Preferences::GetCString("media.audio_loopback_dev", audioLoopDev);
     }
   }
 
   RefPtr<Runnable> task = NewTaskFrom([id, aWindowId, audioLoopDev,
                                        videoLoopDev, aVideoType,
                                        aAudioType, aFake]() mutable {
     // Only enumerate what's asked for, and only fake cams and mics.
     bool hasVideo = aVideoType != MediaSourceEnum::Other;
@@ -1730,25 +1730,27 @@ MediaManager::EnumerateRawDevices(uint64
       realBackend = manager->GetBackend(aWindowId);
     }
 
     auto result = MakeUnique<SourceSet>();
 
     if (hasVideo) {
       nsTArray<RefPtr<VideoDevice>> videos;
       GetSources(fakeCams? fakeBackend : realBackend, aVideoType,
-                 &MediaEngine::EnumerateVideoDevices, videos, videoLoopDev);
+                 &MediaEngine::EnumerateVideoDevices, videos,
+                 videoLoopDev.get());
       for (auto& source : videos) {
         result->AppendElement(source);
       }
     }
     if (hasAudio) {
       nsTArray<RefPtr<AudioDevice>> audios;
       GetSources(fakeMics? fakeBackend : realBackend, aAudioType,
-                 &MediaEngine::EnumerateAudioDevices, audios, audioLoopDev);
+                 &MediaEngine::EnumerateAudioDevices, audios,
+                 audioLoopDev.get());
       for (auto& source : audios) {
         result->AppendElement(source);
       }
     }
     SourceSet* handoff = result.release();
     NS_DispatchToMainThread(NewRunnableFrom([id, handoff]() mutable {
       UniquePtr<SourceSet> result(handoff); // grab result
       RefPtr<MediaManager> mgr = MediaManager_GetInstance();
--- a/dom/media/webspeech/recognition/SpeechRecognition.cpp
+++ b/dom/media/webspeech/recognition/SpeechRecognition.cpp
@@ -67,18 +67,18 @@ GetSpeechRecognitionLog()
 }
 #define SR_LOG(...) MOZ_LOG(GetSpeechRecognitionLog(), mozilla::LogLevel::Debug, (__VA_ARGS__))
 
 already_AddRefed<nsISpeechRecognitionService>
 GetSpeechRecognitionService(const nsAString& aLang)
 {
   nsAutoCString speechRecognitionServiceCID;
 
-  nsAdoptingCString prefValue =
-    Preferences::GetCString(PREFERENCE_DEFAULT_RECOGNITION_SERVICE);
+  nsAutoCString prefValue;
+  Preferences::GetCString(PREFERENCE_DEFAULT_RECOGNITION_SERVICE, prefValue);
   nsAutoCString speechRecognitionService;
 
   if (!aLang.IsEmpty()) {
     speechRecognitionService =
       NS_LITERAL_CSTRING(DEFAULT_RECOGNITION_SERVICE_PREFIX) +
       NS_ConvertUTF16toUTF8(aLang);
   } else if (!prefValue.IsEmpty()) {
     speechRecognitionService = prefValue;
--- a/dom/plugins/base/nsPluginHost.cpp
+++ b/dom/plugins/base/nsPluginHost.cpp
@@ -1549,18 +1549,18 @@ nsPluginHost::RegisterFakePlugin(JS::Han
   for (const auto& existingTag : mFakePlugins) {
     if (newTag->HandlerURIMatches(existingTag->HandlerURI())) {
       return NS_ERROR_UNEXPECTED;
     }
   }
 
   mFakePlugins.AppendElement(newTag);
 
-  nsAdoptingCString disableFullPage =
-    Preferences::GetCString(kPrefDisableFullPage);
+  nsAutoCString disableFullPage;
+  Preferences::GetCString(kPrefDisableFullPage, disableFullPage);
   for (uint32_t i = 0; i < newTag->MimeTypes().Length(); i++) {
     if (!IsTypeInList(newTag->MimeTypes()[i], disableFullPage)) {
       RegisterWithCategoryManager(newTag->MimeTypes()[i],
                                   ePluginRegister);
     }
   }
 
   newTag.forget(aResult);
@@ -1817,18 +1817,19 @@ nsPluginHost::GetSpecialType(const nsACS
   }
 
   // Java registers variants of its MIME with parameters, e.g.
   // application/x-java-vm;version=1.3
   const nsACString &noParam = Substring(aMIMEType, 0, aMIMEType.FindChar(';'));
 
   // The java mime pref may well not be one of these,
   // e.g. application/x-java-test used in the test suite
-  nsAdoptingCString javaMIME = Preferences::GetCString(kPrefJavaMIME);
-  if ((!javaMIME.IsEmpty() && noParam.LowerCaseEqualsASCII(javaMIME)) ||
+  nsAutoCString javaMIME;
+  Preferences::GetCString(kPrefJavaMIME, javaMIME);
+  if ((!javaMIME.IsEmpty() && noParam.LowerCaseEqualsASCII(javaMIME.get())) ||
       noParam.LowerCaseEqualsASCII("application/x-java-vm") ||
       noParam.LowerCaseEqualsASCII("application/x-java-applet") ||
       noParam.LowerCaseEqualsASCII("application/x-java-bean")) {
     return eSpecialType_Java;
   }
 
   return eSpecialType_None;
 }
@@ -2008,18 +2009,18 @@ ShouldAddPlugin(const nsPluginInfo& info
 
 void
 nsPluginHost::AddPluginTag(nsPluginTag* aPluginTag)
 {
   aPluginTag->mNext = mPlugins;
   mPlugins = aPluginTag;
 
   if (aPluginTag->IsActive()) {
-    nsAdoptingCString disableFullPage =
-      Preferences::GetCString(kPrefDisableFullPage);
+    nsAutoCString disableFullPage;
+    Preferences::GetCString(kPrefDisableFullPage, disableFullPage);
     for (uint32_t i = 0; i < aPluginTag->MimeTypes().Length(); i++) {
       if (!IsTypeInList(aPluginTag->MimeTypes()[i], disableFullPage)) {
         RegisterWithCategoryManager(aPluginTag->MimeTypes()[i],
                                     ePluginRegister);
       }
     }
   }
 }
@@ -2402,18 +2403,18 @@ nsPluginHost::SetPluginsInContent(uint32
                                                       mozilla::ipc::DeserializeURI(tag.handlerURI()),
                                                       tag.name().get(),
                                                       tag.description().get(),
                                                       tag.mimeTypes(),
                                                       tag.mimeDescriptions(),
                                                       tag.extensions(),
                                                       tag.niceName(),
                                                       tag.sandboxScript()));
-      nsAdoptingCString disableFullPage =
-        Preferences::GetCString(kPrefDisableFullPage);
+      nsAutoCString disableFullPage;
+      Preferences::GetCString(kPrefDisableFullPage, disableFullPage);
       for (uint32_t i = 0; i < pluginTag->MimeTypes().Length(); i++) {
         if (!IsTypeInList(pluginTag->MimeTypes()[i], disableFullPage)) {
           RegisterWithCategoryManager(pluginTag->MimeTypes()[i],
                                       ePluginRegister);
         }
       }
     }
 
@@ -2650,18 +2651,18 @@ nsPluginHost::UpdateInMemoryPluginInfo(n
   NS_ITERATIVE_UNREF_LIST(RefPtr<nsPluginTag>, mCachedPlugins, mNext);
   NS_ITERATIVE_UNREF_LIST(RefPtr<nsInvalidPluginTag>, mInvalidPlugins, mNext);
 
   if (!aPluginTag) {
     return;
   }
 
   // Update types with category manager
-  nsAdoptingCString disableFullPage =
-    Preferences::GetCString(kPrefDisableFullPage);
+  nsAutoCString disableFullPage;
+  Preferences::GetCString(kPrefDisableFullPage, disableFullPage);
   for (uint32_t i = 0; i < aPluginTag->MimeTypes().Length(); i++) {
     nsRegisterType shouldRegister;
 
     if (IsTypeInList(aPluginTag->MimeTypes()[i], disableFullPage)) {
       shouldRegister = ePluginUnregister;
     } else {
       nsPluginTag *plugin = FindNativePluginForType(aPluginTag->MimeTypes()[i],
                                                     true);
@@ -2689,18 +2690,19 @@ nsPluginHost::UpdatePluginInfo(nsPluginT
   IncrementChromeEpoch();
 
   UpdateInMemoryPluginInfo(aPluginTag);
 }
 
 /* static */ bool
 nsPluginHost::IsTypeWhitelisted(const char *aMimeType)
 {
-  nsAdoptingCString whitelist = Preferences::GetCString(kPrefWhitelist);
-  if (!whitelist.Length()) {
+  nsAutoCString whitelist;
+  Preferences::GetCString(kPrefWhitelist, whitelist);
+  if (whitelist.IsEmpty()) {
     return true;
   }
   nsDependentCString wrap(aMimeType);
   return IsTypeInList(wrap, whitelist);
 }
 
 /* static */ bool
 nsPluginHost::ShouldLoadTypeInParent(const nsACString& aMimeType)
--- a/dom/presentation/provider/MulticastDNSDeviceProvider.cpp
+++ b/dom/presentation/provider/MulticastDNSDeviceProvider.cpp
@@ -155,17 +155,17 @@ MulticastDNSDeviceProvider::Init()
   }
   Preferences::AddStrongObservers(this, kObservedPrefs);
 
   mDiscoveryEnabled = Preferences::GetBool(PREF_PRESENTATION_DISCOVERY);
   mDiscoveryTimeoutMs = Preferences::GetUint(PREF_PRESENTATION_DISCOVERY_TIMEOUT_MS);
   mDiscoverable = Preferences::GetBool(PREF_PRESENTATION_DISCOVERABLE);
   mDiscoverableEncrypted = Preferences::GetBool(PREF_PRESENTATION_DISCOVERABLE_ENCRYPTED);
   mServerRetryMs = Preferences::GetUint(PREF_PRESENTATION_DISCOVERABLE_RETRY_MS);
-  mServiceName = Preferences::GetCString(PREF_PRESENTATION_DEVICE_NAME);
+  Preferences::GetCString(PREF_PRESENTATION_DEVICE_NAME, mServiceName);
 
 #ifdef MOZ_WIDGET_ANDROID
   // FIXME: Bug 1185806 - Provide a common device name setting.
   if (mServiceName.IsEmpty()) {
     GetAndroidDeviceName(mServiceName);
     Unused << Preferences::SetCString(PREF_PRESENTATION_DEVICE_NAME, mServiceName);
   }
 #endif // MOZ_WIDGET_ANDROID
@@ -1093,17 +1093,18 @@ MulticastDNSDeviceProvider::Observe(nsIS
   if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
     if (data.EqualsLiteral(PREF_PRESENTATION_DISCOVERY)) {
       OnDiscoveryChanged(Preferences::GetBool(PREF_PRESENTATION_DISCOVERY));
     } else if (data.EqualsLiteral(PREF_PRESENTATION_DISCOVERY_TIMEOUT_MS)) {
       OnDiscoveryTimeoutChanged(Preferences::GetUint(PREF_PRESENTATION_DISCOVERY_TIMEOUT_MS));
     } else if (data.EqualsLiteral(PREF_PRESENTATION_DISCOVERABLE)) {
       OnDiscoverableChanged(Preferences::GetBool(PREF_PRESENTATION_DISCOVERABLE));
     } else if (data.EqualsLiteral(PREF_PRESENTATION_DEVICE_NAME)) {
-      nsAdoptingCString newServiceName = Preferences::GetCString(PREF_PRESENTATION_DEVICE_NAME);
+      nsAutoCString newServiceName;
+      Preferences::GetCString(PREF_PRESENTATION_DEVICE_NAME, newServiceName);
       if (!mServiceName.Equals(newServiceName)) {
         OnServiceNameChanged(newServiceName);
       }
     }
   } else if (!strcmp(aTopic, NS_TIMER_CALLBACK_TOPIC)) {
     nsCOMPtr<nsITimer> timer = do_QueryInterface(aSubject);
     if (!timer) {
       return NS_ERROR_UNEXPECTED;
--- a/dom/security/nsContentSecurityManager.cpp
+++ b/dom/security/nsContentSecurityManager.cpp
@@ -709,18 +709,20 @@ nsContentSecurityManager::IsOriginPotent
     return NS_OK;
   }
 
   // If a host is not considered secure according to the default algorithm, then
   // check to see if it has been whitelisted by the user.  We only apply this
   // whitelist for network resources, i.e., those with scheme "http" or "ws".
   // The pref should contain a comma-separated list of hostnames.
   if (scheme.EqualsLiteral("http") || scheme.EqualsLiteral("ws")) {
-    nsAdoptingCString whitelist = Preferences::GetCString("dom.securecontext.whitelist");
-    if (whitelist) {
+    nsAutoCString whitelist;
+    nsresult rv =
+      Preferences::GetCString("dom.securecontext.whitelist", whitelist);
+    if (NS_SUCCEEDED(rv)) {
       nsCCharSeparatedTokenizer tokenizer(whitelist, ',');
       while (tokenizer.hasMoreTokens()) {
         const nsACString& allowedHost = tokenizer.nextToken();
         if (host.Equals(allowedHost)) {
           *aIsTrustWorthy = true;
           return NS_OK;
         }
       }
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -271,18 +271,18 @@ HTMLEditRules::Init(TextEditor* aTextEdi
 
   // call through to base class Init
   nsresult rv = TextEditRules::Init(aTextEditor);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // cache any prefs we care about
   static const char kPrefName[] =
     "editor.html.typing.returnInEmptyListItemClosesList";
-  nsAdoptingCString returnInEmptyLIKillsList =
-    Preferences::GetCString(kPrefName);
+  nsAutoCString returnInEmptyLIKillsList;
+  Preferences::GetCString(kPrefName, returnInEmptyLIKillsList);
 
   // only when "false", becomes FALSE.  Otherwise (including empty), TRUE.
   // XXX Why was this pref designed as a string and not bool?
   mReturnInEmptyLIKillsList = !returnInEmptyLIKillsList.EqualsLiteral("false");
 
   // make a utility range for use by the listenter
   nsCOMPtr<nsINode> node = mHTMLEditor->GetRoot();
   if (!node) {
--- a/extensions/cookie/nsPermissionManager.cpp
+++ b/extensions/cookie/nsPermissionManager.cpp
@@ -2852,17 +2852,18 @@ nsPermissionManager::Import()
   return NS_OK;
 }
 
 // ImportDefaults will read a URL with default permissions and add them to the
 // in-memory copy of permissions.  The database is *not* written to.
 nsresult
 nsPermissionManager::ImportDefaults()
 {
-  nsCString defaultsURL = mozilla::Preferences::GetCString(kDefaultsUrlPrefName);
+  nsAutoCString defaultsURL;
+  mozilla::Preferences::GetCString(kDefaultsUrlPrefName, defaultsURL);
   if (defaultsURL.IsEmpty()) { // == Don't use built-in permissions.
     return NS_OK;
   }
 
   nsCOMPtr<nsIURI> defaultsURI;
   nsresult rv = NS_NewURI(getter_AddRefs(defaultsURI), defaultsURL);
   NS_ENSURE_SUCCESS(rv, rv);
 
--- a/gfx/gl/GLLibraryEGL.cpp
+++ b/gfx/gl/GLLibraryEGL.cpp
@@ -73,18 +73,18 @@ static PRLibrary* LoadApitraceLibrary()
         return nullptr;
     }
 
     static PRLibrary* sApitraceLibrary = nullptr;
 
     if (sApitraceLibrary)
         return sApitraceLibrary;
 
-    nsCString logFile = Preferences::GetCString("gfx.apitrace.logfile");
-
+    nsAutoCString logFile;
+    Preferences::GetCString("gfx.apitrace.logfile", logFile);
     if (logFile.IsEmpty()) {
         logFile = "firefox.trace";
     }
 
     // The firefox process can't write to /data/local, but it can write
     // to $GRE_HOME/
     nsAutoCString logPath;
     logPath.AppendPrintf("%s/%s", getenv("GRE_HOME"), logFile.get());
--- a/gfx/thebes/gfxDWriteFontList.cpp
+++ b/gfx/thebes/gfxDWriteFontList.cpp
@@ -986,19 +986,21 @@ gfxDWriteFontList::InitFontListForPlatfo
                 }
             }
 
             // remove Gills Sans
             mFontFamilies.Remove(nameGillSans);
         }
     }
 
-    nsAdoptingCString classicFamilies =
-        Preferences::GetCString("gfx.font_rendering.cleartype_params.force_gdi_classic_for_families");
-    if (classicFamilies) {
+    nsAutoCString classicFamilies;
+    nsresult rv = Preferences::GetCString(
+      "gfx.font_rendering.cleartype_params.force_gdi_classic_for_families",
+      classicFamilies);
+    if (NS_SUCCEEDED(rv)) {
         nsCCharSeparatedTokenizer tokenizer(classicFamilies, ',');
         while (tokenizer.hasMoreTokens()) {
             NS_ConvertUTF8toUTF16 name(tokenizer.nextToken());
             BuildKeyNameFromFontName(name);
             gfxFontFamily *family = mFontFamilies.GetWeak(name);
             if (family) {
                 static_cast<gfxDWriteFontFamily*>(family)->SetForceGDIClassic(true);
             }
--- a/gfx/thebes/gfxFcPlatformFontList.cpp
+++ b/gfx/thebes/gfxFcPlatformFontList.cpp
@@ -1897,25 +1897,25 @@ gfxFcPlatformFontList::PrefFontListsUseO
             //       font.name-list.serif.ar ==> "Something, serif"
             //                                           (return false)
 
             nsDependentCString prefName(names[i] +
                                         ArrayLength(kFontNamePrefix) - 1);
             nsCCharSeparatedTokenizer tokenizer(prefName, '.');
             const nsDependentCSubstring& generic = tokenizer.nextToken();
             const nsDependentCSubstring& langGroup = tokenizer.nextToken();
-            nsAdoptingCString fontPrefValue = Preferences::GetCString(names[i]);
+            nsAutoCString fontPrefValue;
+            Preferences::GetCString(names[i], fontPrefValue);
             if (fontPrefValue.IsEmpty()) {
                 // The font name list may have two or more family names as comma
                 // separated list.  In such case, not matching with generic font
                 // name is fine because if the list prefers specific font, this
                 // should return false.
-                fontPrefValue =
-                    Preferences::GetCString(NameListPref(generic,
-                                                         langGroup).get());
+                Preferences::GetCString(NameListPref(generic, langGroup).get(),
+                                        fontPrefValue);
             }
 
             if (!langGroup.EqualsLiteral("x-math") &&
                 !generic.Equals(fontPrefValue)) {
                 prefFontsUseOnlyGenerics = false;
                 break;
             }
         }
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -640,18 +640,22 @@ gfxPlatform::Init()
 
     if (XRE_IsParentProcess()) {
       GPUProcessManager::Initialize();
 
       if (Preferences::GetBool("media.wmf.skip-blacklist")) {
         gfxVars::SetPDMWMFDisableD3D11Dlls(nsCString());
         gfxVars::SetPDMWMFDisableD3D9Dlls(nsCString());
       } else {
-        gfxVars::SetPDMWMFDisableD3D11Dlls(Preferences::GetCString("media.wmf.disable-d3d11-for-dlls"));
-        gfxVars::SetPDMWMFDisableD3D9Dlls(Preferences::GetCString("media.wmf.disable-d3d9-for-dlls"));
+        nsAutoCString d3d11;
+        Preferences::GetCString("media.wmf.disable-d3d11-for-dlls", d3d11);
+        gfxVars::SetPDMWMFDisableD3D11Dlls(d3d11);
+        nsAutoCString d3d9;
+        Preferences::GetCString("media.wmf.disable-d3d9-for-dlls", d3d9);
+        gfxVars::SetPDMWMFDisableD3D9Dlls(d3d9);
       }
 
       nsCOMPtr<nsIFile> file;
       nsresult rv = NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(file));
       if (NS_FAILED(rv)) {
         gfxVars::SetGREDirectory(nsCString());
       } else {
         nsAutoCString nativePath;
@@ -1937,19 +1941,20 @@ gfxPlatform::GetPlatformCMSOutputProfile
 {
     mem = nullptr;
     size = 0;
 }
 
 void
 gfxPlatform::GetCMSOutputProfileData(void *&mem, size_t &size)
 {
-    nsAdoptingCString fname = Preferences::GetCString("gfx.color_management.display_profile");
+    nsAutoCString fname;
+    Preferences::GetCString("gfx.color_management.display_profile", fname);
     if (!fname.IsEmpty()) {
-        qcms_data_from_path(fname, &mem, &size);
+        qcms_data_from_path(fname.get(), &mem, &size);
     }
     else {
         gfxPlatform::GetPlatform()->GetPlatformCMSOutputProfile(mem, size);
     }
 }
 
 void
 gfxPlatform::CreateCMSOutputProfile()
--- a/gfx/thebes/gfxPlatformFontList.cpp
+++ b/gfx/thebes/gfxPlatformFontList.cpp
@@ -1084,17 +1084,18 @@ gfxPlatformFontList::AppendCJKPrefLangs(
     // if not set up, set up the default CJK order, based on accept lang settings and locale
     if (mCJKPrefLangs.Length() == 0) {
 
         // temp array
         eFontPrefLang tempPrefLangs[kMaxLenPrefLangList];
         uint32_t tempLen = 0;
 
         // Add the CJK pref fonts from accept languages, the order should be same order
-        nsAdoptingCString list = Preferences::GetLocalizedCString("intl.accept_languages");
+        nsAutoCString list;
+        Preferences::GetLocalizedCString("intl.accept_languages", list);
         if (!list.IsEmpty()) {
             const char kComma = ',';
             const char *p, *p_end;
             list.BeginReading(p);
             list.EndReading(p_end);
             while (p < p_end) {
                 while (nsCRT::IsAsciiSpace(*p)) {
                     if (++p == p_end)
@@ -1210,18 +1211,18 @@ mozilla::FontFamilyType
 gfxPlatformFontList::GetDefaultGeneric(eFontPrefLang aLang)
 {
     // initialize lang group pref font defaults (i.e. serif/sans-serif)
     if (MOZ_UNLIKELY(mDefaultGenericsLangGroup.IsEmpty())) {
         mDefaultGenericsLangGroup.AppendElements(ArrayLength(gPrefLangNames));
         for (uint32_t i = 0; i < ArrayLength(gPrefLangNames); i++) {
             nsAutoCString prefDefaultFontType("font.default.");
             prefDefaultFontType.Append(GetPrefLangName(eFontPrefLang(i)));
-            nsAdoptingCString serifOrSans =
-                Preferences::GetCString(prefDefaultFontType.get());
+            nsAutoCString serifOrSans;
+            Preferences::GetCString(prefDefaultFontType.get(), serifOrSans);
             if (serifOrSans.EqualsLiteral("sans-serif")) {
                 mDefaultGenericsLangGroup[i] = eFamily_sans_serif;
             } else {
                 mDefaultGenericsLangGroup[i] = eFamily_serif;
             }
         }
     }
 
--- a/gfx/vr/gfxVROSVR.cpp
+++ b/gfx/vr/gfxVROSVR.cpp
@@ -110,28 +110,26 @@ static pfn_osvrClientSetRoomRotationUsin
 bool
 LoadOSVRRuntime()
 {
   static PRLibrary* osvrUtilLib = nullptr;
   static PRLibrary* osvrCommonLib = nullptr;
   static PRLibrary* osvrClientLib = nullptr;
   static PRLibrary* osvrClientKitLib = nullptr;
   //this looks up the path in the about:config setting, from greprefs.js or modules\libpref\init\all.js
-  nsAdoptingCString osvrUtilPath =
-    mozilla::Preferences::GetCString("gfx.vr.osvr.utilLibPath");
-  nsAdoptingCString osvrCommonPath =
-    mozilla::Preferences::GetCString("gfx.vr.osvr.commonLibPath");
-  nsAdoptingCString osvrClientPath =
-    mozilla::Preferences::GetCString("gfx.vr.osvr.clientLibPath");
-  nsAdoptingCString osvrClientKitPath =
-    mozilla::Preferences::GetCString("gfx.vr.osvr.clientKitLibPath");
-
   //we need all the libs to be valid
-  if ((!osvrUtilPath) || (!osvrCommonPath) || (!osvrClientPath) ||
-      (!osvrClientKitPath)) {
+  nsAutoCString osvrUtilPath, osvrCommonPath, osvrClientPath, osvrClientKitPath;
+  if (NS_FAILED(mozilla::Preferences::GetCString("gfx.vr.osvr.utilLibPath",
+                                                 osvrUtilPath)) ||
+      NS_FAILED(mozilla::Preferences::GetCString("gfx.vr.osvr.commonLibPath",
+                                                 osvrCommonPath)) ||
+      NS_FAILED(mozilla::Preferences::GetCString("gfx.vr.osvr.clientLibPath",
+                                                 osvrClientPath)) ||
+      NS_FAILED(mozilla::Preferences::GetCString("gfx.vr.osvr.clientKitLibPath",
+                                                 osvrClientKitPath))) {
     return false;
   }
 
   osvrUtilLib = PR_LoadLibrary(osvrUtilPath.BeginReading());
   osvrCommonLib = PR_LoadLibrary(osvrCommonPath.BeginReading());
   osvrClientLib = PR_LoadLibrary(osvrClientPath.BeginReading());
   osvrClientKitLib = PR_LoadLibrary(osvrClientKitPath.BeginReading());
 
--- a/image/imgLoader.cpp
+++ b/image/imgLoader.cpp
@@ -1339,22 +1339,23 @@ imgLoader::Observe(nsISupports* aSubject
     MOZ_ASSERT(0, "Invalid topic received");
   }
 
   return NS_OK;
 }
 
 void imgLoader::ReadAcceptHeaderPref()
 {
-  nsAdoptingCString accept = Preferences::GetCString("image.http.accept");
-  if (accept) {
+  nsAutoCString accept;
+  nsresult rv = Preferences::GetCString("image.http.accept", accept);
+  if (NS_SUCCEEDED(rv)) {
     mAcceptHeader = accept;
   } else {
     mAcceptHeader =
-        IMAGE_PNG "," IMAGE_WILDCARD ";q=0.8," ANY_WILDCARD ";q=0.5";
+      IMAGE_PNG "," IMAGE_WILDCARD ";q=0.8," ANY_WILDCARD ";q=0.5";
   }
 }
 
 NS_IMETHODIMP
 imgLoader::ClearCache(bool chrome)
 {
   if (XRE_IsParentProcess()) {
     bool privateLoader = this == gPrivateBrowsingLoader;
--- a/intl/hyphenation/glue/nsHyphenationManager.cpp
+++ b/intl/hyphenation/glue/nsHyphenationManager.cpp
@@ -300,18 +300,19 @@ nsHyphenationManager::LoadAliases()
     return;
   }
   uint32_t prefCount;
   char **prefNames;
   nsresult rv = prefRootBranch->GetChildList(kIntlHyphenationAliasPrefix,
                                              &prefCount, &prefNames);
   if (NS_SUCCEEDED(rv) && prefCount > 0) {
     for (uint32_t i = 0; i < prefCount; ++i) {
-      nsAdoptingCString value = Preferences::GetCString(prefNames[i]);
-      if (value) {
+      nsAutoCString value;
+      rv = Preferences::GetCString(prefNames[i], value);
+      if (NS_SUCCEEDED(rv)) {
         nsAutoCString alias(prefNames[i]);
         alias.Cut(0, sizeof(kIntlHyphenationAliasPrefix) - 1);
         ToLowerCase(alias);
         ToLowerCase(value);
         nsCOMPtr<nsIAtom> aliasAtom = NS_Atomize(alias);
         nsCOMPtr<nsIAtom> valueAtom = NS_Atomize(value);
         mHyphAliases.Put(aliasAtom, valueAtom);
       }
--- a/intl/locale/android/OSPreferences_android.cpp
+++ b/intl/locale/android/OSPreferences_android.cpp
@@ -14,17 +14,18 @@ OSPreferences::ReadSystemLocales(nsTArra
 {
   //XXX: This is a quite sizable hack to work around the fact that we cannot
   //     retrieve OS locale in C++ without reaching out to JNI.
   //     Once we fix this (bug 1337078), this hack should not be necessary.
   //
   //XXX: Notice, this value may be empty on an early read. In that case
   //     we won't add anything to the return list so that it doesn't get
   //     cached in mSystemLocales.
-  nsAdoptingCString locale = Preferences::GetCString("intl.locale.os");
+  nsAutoCString locale;
+  Preferences::GetCString("intl.locale.os", locale);
   if (!locale.IsEmpty()) {
     aLocaleList.AppendElement(locale);
     return true;
   }
   return false;
 }
 
 bool
--- a/js/ipc/JavaScriptParent.cpp
+++ b/js/ipc/JavaScriptParent.cpp
@@ -68,19 +68,21 @@ ForbidUnsafeBrowserCPOWs()
 static bool
 ForbidCPOWsInCompatibleAddon(const nsACString& aAddonId)
 {
     bool forbid = Preferences::GetBool("dom.ipc.cpows.forbid-cpows-in-compat-addons", false);
     if (!forbid) {
         return false;
     }
 
-    nsCString allow;
+    nsAutoCString allow;
     allow.Assign(',');
-    allow.Append(Preferences::GetCString("dom.ipc.cpows.allow-cpows-in-compat-addons"));
+    nsAutoCString pref;
+    Preferences::GetCString("dom.ipc.cpows.allow-cpows-in-compat-addons", pref);
+    allow.Append(pref);
     allow.Append(',');
 
     nsCString searchString(",");
     searchString.Append(aAddonId);
     searchString.Append(',');
     return allow.Find(searchString) == kNotFound;
 }
 
--- a/layout/base/StaticPresData.cpp
+++ b/layout/base/StaticPresData.cpp
@@ -98,18 +98,18 @@ LangGroupFontPrefs::Initialize(nsIAtom* 
   mDefaultFixedFont.size = nsPresContext::CSSPixelsToAppUnits(13);
 
   nsAutoCString pref;
 
   // get the current applicable font-size unit
   enum {eUnit_unknown = -1, eUnit_px, eUnit_pt};
   int32_t unit = eUnit_px;
 
-  nsAdoptingCString cvalue =
-    Preferences::GetCString("font.size.unit");
+  nsAutoCString cvalue;
+  Preferences::GetCString("font.size.unit", cvalue);
 
   if (!cvalue.IsEmpty()) {
     if (cvalue.EqualsLiteral("px")) {
       unit = eUnit_px;
     }
     else if (cvalue.EqualsLiteral("pt")) {
       unit = eUnit_pt;
     }
@@ -217,17 +217,17 @@ LangGroupFontPrefs::Initialize(nsIAtom* 
       else if (unit == eUnit_pt) {
         font->size = nsPresContext::CSSPointsToAppUnits(size);
       }
     }
 
     // get font.size-adjust.[generic].[langGroup]
     // XXX only applicable on GFX ports that handle |font-size-adjust|
     MAKE_FONT_PREF_KEY(pref, "font.size-adjust", generic_dot_langGroup);
-    cvalue = Preferences::GetCString(pref.get());
+    Preferences::GetCString(pref.get(), cvalue);
     if (!cvalue.IsEmpty()) {
       font->sizeAdjust = (float)atof(cvalue.get());
     }
 
 #ifdef DEBUG_rbs
     printf("%s Family-list:%s size:%d sizeAdjust:%.2f\n",
            generic_dot_langGroup.get(),
            NS_ConvertUTF16toUTF8(font->name).get(), font->size,
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -631,18 +631,18 @@ nsPresContext::GetUserPreferences()
 
   mPrefScrollbarSide = Preferences::GetInt("layout.scrollbar.side");
 
   mLangGroupFontPrefs.Reset();
   mFontGroupCacheDirty = true;
   StaticPresData::Get()->ResetCachedFontPrefs();
 
   // * image animation
-  const nsAdoptingCString& animatePref =
-    Preferences::GetCString("image.animation_mode");
+  nsAutoCString animatePref;
+  Preferences::GetCString("image.animation_mode", animatePref);
   if (animatePref.EqualsLiteral("normal"))
     mImageAnimationModePref = imgIContainer::kNormalAnimMode;
   else if (animatePref.EqualsLiteral("none"))
     mImageAnimationModePref = imgIContainer::kDontAnimMode;
   else if (animatePref.EqualsLiteral("once"))
     mImageAnimationModePref = imgIContainer::kLoopOnceAnimMode;
   else // dynamic change to invalid value should act like it does initially
     mImageAnimationModePref = imgIContainer::kNormalAnimMode;
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -1600,17 +1600,19 @@ static nsresult pref_InitInitialObjects(
   // channel, telemetry is on by default, otherwise not. This is necessary
   // so that beta users who are testing final release builds don't flipflop
   // defaults.
   if (Preferences::GetDefaultType(kTelemetryPref) == nsIPrefBranch::PREF_INVALID) {
     bool prerelease = false;
 #ifdef MOZ_TELEMETRY_ON_BY_DEFAULT
     prerelease = true;
 #else
-    if (Preferences::GetDefaultCString(kChannelPref).EqualsLiteral("beta")) {
+    nsAutoCString prefValue;
+    Preferences::GetDefaultCString(kChannelPref, prefValue);
+    if (prefValue.EqualsLiteral("beta")) {
       prerelease = true;
     }
 #endif
     PREF_SetBoolPref(kTelemetryPref, prerelease, true);
   }
 
   NS_CreateServicesFromCategory(NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID,
                                 nullptr, NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID);
@@ -1661,33 +1663,24 @@ Preferences::GetFloat(const char* aPref,
   if (NS_SUCCEEDED(rv)) {
     *aResult = result.ToFloat(&rv);
   }
 
   return rv;
 }
 
 // static
-nsAdoptingCString
-Preferences::GetCString(const char* aPref)
-{
-  nsAdoptingCString result;
-  PREF_CopyCharPref(aPref, getter_Copies(result), false);
-  return result;
-}
-
-// static
 nsresult
 Preferences::GetCString(const char* aPref, nsACString& aResult)
 {
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
-  nsAutoCString result;
-  nsresult rv = PREF_CopyCharPref(aPref, getter_Copies(result), false);
+  char* result;
+  nsresult rv = PREF_CopyCharPref(aPref, &result, false);
   if (NS_SUCCEEDED(rv)) {
-    aResult = result;
+    aResult.Adopt(result);
   }
   return rv;
 }
 
 // static
 nsresult
 Preferences::GetString(const char* aPref, nsAString& aResult)
 {
@@ -1696,25 +1689,16 @@ Preferences::GetString(const char* aPref
   nsresult rv = PREF_CopyCharPref(aPref, getter_Copies(result), false);
   if (NS_SUCCEEDED(rv)) {
     CopyUTF8toUTF16(result, aResult);
   }
   return rv;
 }
 
 // static
-nsAdoptingCString
-Preferences::GetLocalizedCString(const char* aPref)
-{
-  nsAdoptingCString result;
-  GetLocalizedCString(aPref, result);
-  return result;
-}
-
-// static
 nsresult
 Preferences::GetLocalizedCString(const char* aPref, nsACString& aResult)
 {
   nsAutoString result;
   nsresult rv = GetLocalizedString(aPref, result);
   if (NS_SUCCEEDED(rv)) {
     CopyUTF16toUTF8(result, aResult);
   }
@@ -2174,20 +2158,20 @@ Preferences::GetDefaultInt(const char* a
   return PREF_GetIntPref(aPref, aResult, true);
 }
 
 // static
 nsresult
 Preferences::GetDefaultCString(const char* aPref, nsACString& aResult)
 {
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
-  nsAutoCString result;
-  nsresult rv = PREF_CopyCharPref(aPref, getter_Copies(result), true);
+  char* result;
+  nsresult rv = PREF_CopyCharPref(aPref, &result, true);
   if (NS_SUCCEEDED(rv)) {
-    aResult = result;
+    aResult.Adopt(result);
   }
   return rv;
 }
 
 // static
 nsresult
 Preferences::GetDefaultString(const char* aPref, nsAString& aResult)
 {
@@ -2227,34 +2211,16 @@ Preferences::GetDefaultLocalizedString(c
   if (NS_SUCCEEDED(rv)) {
     NS_ASSERTION(prefLocalString, "Succeeded but the result is NULL");
     prefLocalString->GetData(getter_Copies(aResult));
   }
   return rv;
 }
 
 // static
-nsAdoptingCString
-Preferences::GetDefaultCString(const char* aPref)
-{
-  nsAdoptingCString result;
-  PREF_CopyCharPref(aPref, getter_Copies(result), true);
-  return result;
-}
-
-// static
-nsAdoptingCString
-Preferences::GetDefaultLocalizedCString(const char* aPref)
-{
-  nsAdoptingCString result;
-  GetDefaultLocalizedCString(aPref, result);
-  return result;
-}
-
-// static
 nsresult
 Preferences::GetDefaultComplex(const char* aPref, const nsIID &aType,
                                void** aResult)
 {
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
   return sDefaultRootBranch->GetComplexValue(aPref, aType, aResult);
 }
 
--- a/modules/libpref/Preferences.h
+++ b/modules/libpref/Preferences.h
@@ -16,17 +16,16 @@
 #include "nsIObserver.h"
 #include "nsCOMPtr.h"
 #include "nsTArray.h"
 #include "nsWeakReference.h"
 #include "mozilla/Atomics.h"
 #include "mozilla/MemoryReporting.h"
 
 class nsIFile;
-class nsAdoptingCString;
 
 #ifndef have_PrefChangedFunc_typedef
 typedef void (*PrefChangedFunc)(const char *, void *);
 #define have_PrefChangedFunc_typedef
 #endif
 
 #ifdef DEBUG
 enum pref_initPhase {
@@ -143,40 +142,16 @@ public:
   static float GetFloat(const char* aPref, float aDefault = 0)
   {
     float result = aDefault;
     GetFloat(aPref, &result);
     return result;
   }
 
   /**
-   * Gets char type pref value directly.  If failed, the get() of result
-   * returns nullptr.  Even if succeeded but the result was empty string, the
-   * get() does NOT return nullptr.  So, you can check whether the method
-   * succeeded or not by:
-   *
-   * nsAdoptingString value = Prefereces::GetString("foo.bar");
-   * if (!value) {
-   *   // failed
-   * }
-   *
-   * Be aware.  If you wrote as:
-   *
-   * nsAutoString value = Preferences::GetString("foo.bar");
-   * if (!value.get()) {
-   *   // the condition is always FALSE!!
-   * }
-   *
-   * The value.get() doesn't return nullptr. You must use nsAdoptingString
-   * when you need to check whether it was failure or not.
-   */
-  static nsAdoptingCString GetCString(const char* aPref);
-  static nsAdoptingCString GetLocalizedCString(const char* aPref);
-
-  /**
    * Gets int, float, or bool type pref value with raw return value of
    * nsIPrefBranch.
    *
    * @param aPref       A pref name.
    * @param aResult     Must not be nullptr.  The value is never modified
    *                    when these methods fail.
    */
   static nsresult GetBool(const char* aPref, bool* aResult);
@@ -373,25 +348,17 @@ public:
   static uint32_t GetDefaultUint(const char* aPref, uint32_t aFailedResult)
   {
    return static_cast<uint32_t>(
      GetDefaultInt(aPref, static_cast<int32_t>(aFailedResult)));
   }
 
   /**
    * Gets the default value of the char type pref.
-   * If the get() of the result returned nullptr, that meant the value didn't
-   * have default value.
-   *
-   * See the comment at definition at GetString() and GetCString() for more
-   * details of the result.
    */
-  static nsAdoptingCString GetDefaultCString(const char* aPref);
-  static nsAdoptingCString GetDefaultLocalizedCString(const char* aPref);
-
   static nsresult GetDefaultCString(const char* aPref, nsACString& aResult);
   static nsresult GetDefaultString(const char* aPref, nsAString& aResult);
   static nsresult GetDefaultLocalizedCString(const char* aPref,
                                              nsACString& aResult);
   static nsresult GetDefaultLocalizedString(const char* aPref,
                                             nsAString& aResult);
 
   static nsresult GetDefaultComplex(const char* aPref, const nsIID &aType,
--- a/netwerk/base/nsChannelClassifier.cpp
+++ b/netwerk/base/nsChannelClassifier.cpp
@@ -115,24 +115,28 @@ StaticAutoPtr<CachedPrefs> CachedPrefs::
 
 // static
 void
 CachedPrefs::OnPrefsChange(const char* aPref, void* aClosure)
 {
   CachedPrefs* prefs = static_cast<CachedPrefs*> (aClosure);
 
   if (!strcmp(aPref, URLCLASSIFIER_SKIP_HOSTNAMES)) {
-    nsCString skipHostnames = Preferences::GetCString(URLCLASSIFIER_SKIP_HOSTNAMES);
+    nsCString skipHostnames;
+    Preferences::GetCString(URLCLASSIFIER_SKIP_HOSTNAMES, skipHostnames);
     ToLowerCase(skipHostnames);
     prefs->SetSkipHostnames(skipHostnames);
   } else if (!strcmp(aPref, URLCLASSIFIER_TRACKING_WHITELIST)) {
-    nsCString trackingWhitelist = Preferences::GetCString(URLCLASSIFIER_TRACKING_WHITELIST);
+    nsCString trackingWhitelist;
+    Preferences::GetCString(URLCLASSIFIER_TRACKING_WHITELIST,
+                            trackingWhitelist);
     prefs->SetTrackingWhiteList(trackingWhitelist);
   } else if (!strcmp(aPref, URLCLASSIFIER_TRACKING_TABLE)) {
-    nsCString trackingBlacklist = Preferences::GetCString(URLCLASSIFIER_TRACKING_TABLE);
+    nsCString trackingBlacklist;
+    Preferences::GetCString(URLCLASSIFIER_TRACKING_TABLE, trackingBlacklist);
     prefs->SetTrackingBlackList(trackingBlacklist);
   }
 }
 
 void
 CachedPrefs::Init()
 {
   Preferences::AddBoolVarCache(&sAnnotateChannelEnabled,
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -1995,18 +1995,18 @@ PrepareAcceptLanguages(const char *i_Acc
     return NS_OK;
 }
 
 nsresult
 nsHttpHandler::SetAcceptLanguages()
 {
     mAcceptLanguagesIsDirty = false;
 
-    const nsAdoptingCString& acceptLanguages =
-        Preferences::GetLocalizedCString(INTL_ACCEPT_LANGUAGES);
+    nsAutoCString acceptLanguages;
+    Preferences::GetLocalizedCString(INTL_ACCEPT_LANGUAGES, acceptLanguages);
 
     nsAutoCString buf;
     nsresult rv = PrepareAcceptLanguages(acceptLanguages.get(), buf);
     if (NS_SUCCEEDED(rv)) {
         mAcceptLanguages.Assign(buf);
     }
     return rv;
 }
--- a/parser/html/nsHtml5StreamParser.cpp
+++ b/parser/html/nsHtml5StreamParser.cpp
@@ -199,18 +199,18 @@ nsHtml5StreamParser::nsHtml5StreamParser
     mTokenizer->EnableViewSource(highlighter); // takes ownership
     mTreeBuilder->EnableViewSource(highlighter); // doesn't own
   }
 
   // Chardet instantiation adapted from File.
   // Chardet is initialized here even if it turns out to be useless
   // to make the chardet refcount its observer (nsHtml5StreamParser)
   // on the main thread.
-  const nsAdoptingCString& detectorName =
-    Preferences::GetLocalizedCString("intl.charset.detector");
+  nsAutoCString detectorName;
+  Preferences::GetLocalizedCString("intl.charset.detector", detectorName);
   if (!detectorName.IsEmpty()) {
     nsAutoCString detectorContractID;
     detectorContractID.AssignLiteral(NS_CHARSET_DETECTOR_CONTRACTID_BASE);
     detectorContractID += detectorName;
     if ((mChardet = do_CreateInstance(detectorContractID.get()))) {
       (void) mChardet->Init(this);
       mFeedChardet = true;
     }
--- a/security/apps/AppTrustDomain.cpp
+++ b/security/apps/AppTrustDomain.cpp
@@ -80,18 +80,19 @@ AppTrustDomain::SetTrustedRoot(AppTruste
     case nsIX509CertDB::DeveloperImportedRoot: {
       StaticMutexAutoLock lock(sMutex);
       if (!sDevImportedDERData) {
         MOZ_ASSERT(!NS_IsMainThread());
         nsCOMPtr<nsIFile> file(do_CreateInstance("@mozilla.org/file/local;1"));
         if (!file) {
           return NS_ERROR_FAILURE;
         }
-        nsresult rv = file->InitWithNativePath(
-          Preferences::GetCString(kDevImportedDER));
+        nsAutoCString path;
+        Preferences::GetCString(kDevImportedDER, path);
+        nsresult rv = file->InitWithNativePath(path);
         if (NS_FAILED(rv)) {
           return rv;
         }
 
         nsCOMPtr<nsIInputStream> inputStream;
         rv = NS_NewLocalFileInputStream(getter_AddRefs(inputStream), file, -1,
                                         -1, nsIFileInputStream::CLOSE_ON_EOF);
         if (NS_FAILED(rv)) {
--- a/security/sandbox/linux/broker/SandboxBrokerPolicyFactory.cpp
+++ b/security/sandbox/linux/broker/SandboxBrokerPolicyFactory.cpp
@@ -230,38 +230,41 @@ SandboxBrokerPolicyFactory::GetContentPo
   policy->AddPath(rdonly, nsPrintfCString("/proc/%d/maps", aPid).get());
 
   // Bug 1198552: memory reporting.
   policy->AddPath(rdonly, nsPrintfCString("/proc/%d/statm", aPid).get());
   policy->AddPath(rdonly, nsPrintfCString("/proc/%d/smaps", aPid).get());
   // Now read any extra paths, this requires accessing user preferences
   // so we can only do it now. Our constructor is initialized before
   // user preferences are read in.
-  nsAdoptingCString extraReadPathString =
-    Preferences::GetCString("security.sandbox.content.read_path_whitelist");
-  AddDynamicPathList(policy.get(), extraReadPathString, rdonly);
-  nsAdoptingCString extraWritePathString =
-    Preferences::GetCString("security.sandbox.content.write_path_whitelist");
-  AddDynamicPathList(policy.get(), extraWritePathString, rdwr);
+  AddDynamicPathList(policy.get(),
+                     "security.sandbox.content.read_path_whitelist",
+                     rdonly);
+  AddDynamicPathList(policy.get(),
+                     "security.sandbox.content.write_path_whitelist",
+                     rdwr);
 
   // file:// processes get global read permissions
   if (aFileProcess) {
     policy->AddDir(rdonly, "/");
   }
 
   // Return the common policy.
   return policy;
 
 }
 
 void
 SandboxBrokerPolicyFactory::AddDynamicPathList(SandboxBroker::Policy *policy,
-                                               nsAdoptingCString& pathList,
-                                               int perms) {
- if (pathList) {
+                                               const char* aPathListPref,
+                                               int perms)
+{
+  nsAutoCString pathList;
+  nsresult rv = Preferences::GetCString(aPathListPref, pathList);
+  if (NS_SUCCEEDED(rv)) {
     for (const nsACString& path : pathList.Split(',')) {
       nsCString trimPath(path);
       trimPath.Trim(" ", true, true);
       policy->AddDynamic(perms, trimPath.get());
     }
   }
 }
 
--- a/security/sandbox/linux/broker/SandboxBrokerPolicyFactory.h
+++ b/security/sandbox/linux/broker/SandboxBrokerPolicyFactory.h
@@ -17,15 +17,15 @@ public:
 
 #ifdef MOZ_CONTENT_SANDBOX
   UniquePtr<SandboxBroker::Policy> GetContentPolicy(int aPid, bool aFileProcess);
 #endif
 
 private:
   UniquePtr<const SandboxBroker::Policy> mCommonContentPolicy;
   static void AddDynamicPathList(SandboxBroker::Policy *policy,
-                                 nsAdoptingCString& paths,
+                                 const char* aPathListPref,
                                  int perms);
 };
 
 } // namespace mozilla
 
 #endif // mozilla_SandboxBrokerPolicyFactory_h
--- a/uriloader/exthandler/nsExternalHelperAppService.cpp
+++ b/uriloader/exthandler/nsExternalHelperAppService.cpp
@@ -2504,17 +2504,18 @@ void nsExternalAppHandler::ProcessAnyRef
      }
      mOriginalChannel = nullptr;
    }
 }
 
 bool nsExternalAppHandler::GetNeverAskFlagFromPref(const char * prefName, const char * aContentType)
 {
   // Search the obsolete pref strings.
-  nsAdoptingCString prefCString = Preferences::GetCString(prefName);
+  nsAutoCString prefCString;
+  Preferences::GetCString(prefName, prefCString);
   if (prefCString.IsEmpty()) {
     // Default is true, if not found in the pref string.
     return true;
   }
 
   NS_UnescapeURL(prefCString);
   nsACString::const_iterator start, end;
   prefCString.BeginReading(start);
--- a/widget/GfxInfoBase.cpp
+++ b/widget/GfxInfoBase.cpp
@@ -201,18 +201,19 @@ GetPrefValueForFeature(int32_t aFeature,
 
   aValue = nsIGfxInfo::FEATURE_STATUS_UNKNOWN;
   if (!NS_SUCCEEDED(Preferences::GetInt(prefname, &aValue))) {
     return false;
   }
 
   nsCString failureprefname(prefname);
   failureprefname += ".failureid";
-  nsAdoptingCString failureValue = Preferences::GetCString(failureprefname.get());
-  if (failureValue) {
+  nsAutoCString failureValue;
+  nsresult rv = Preferences::GetCString(failureprefname.get(), failureValue);
+  if (NS_SUCCEEDED(rv)) {
     aFailureId = failureValue.get();
   } else {
     aFailureId = "FEATURE_FAILURE_BLACKLIST_PREF";
   }
 
   return true;
 }
 
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -1253,39 +1253,39 @@ nsWindow::GeckoViewSupport::Open(const j
 {
     MOZ_ASSERT(NS_IsMainThread());
 
     AUTO_PROFILER_LABEL("nsWindow::GeckoViewSupport::Open", OTHER);
 
     nsCOMPtr<nsIWindowWatcher> ww = do_GetService(NS_WINDOWWATCHER_CONTRACTID);
     MOZ_RELEASE_ASSERT(ww);
 
-    nsAdoptingCString url;
+    nsAutoCString url;
     if (aChromeURI) {
         url = aChromeURI->ToCString();
     } else {
-        url = Preferences::GetCString("toolkit.defaultChromeURI");
-        if (!url) {
+        nsresult rv = Preferences::GetCString("toolkit.defaultChromeURI", url);
+        if (NS_FAILED(rv)) {
             url = NS_LITERAL_CSTRING("chrome://geckoview/content/geckoview.xul");
         }
     }
 
     RefPtr<AndroidView> androidView = new AndroidView();
     androidView->mEventDispatcher->Attach(
             java::EventDispatcher::Ref::From(aDispatcher), nullptr);
     if (aSettings) {
         androidView->mSettings = java::GeckoBundle::Ref::From(aSettings);
     }
 
     nsAutoCString chromeFlags("chrome,dialog=0,resizable,scrollbars");
     if (aPrivateMode) {
         chromeFlags += ",private";
     }
     nsCOMPtr<mozIDOMWindowProxy> domWindow;
-    ww->OpenWindow(nullptr, url, nullptr, chromeFlags.get(),
+    ww->OpenWindow(nullptr, url.get(), nullptr, chromeFlags.get(),
                    androidView, getter_AddRefs(domWindow));
     MOZ_RELEASE_ASSERT(domWindow);
 
     nsCOMPtr<nsPIDOMWindowOuter> pdomWindow =
             nsPIDOMWindowOuter::From(domWindow);
     nsCOMPtr<nsIWidget> widget = WidgetUtils::DOMWindowToWidget(pdomWindow);
     MOZ_ASSERT(widget);
 
--- a/widget/gtk/nsLookAndFeel.cpp
+++ b/widget/gtk/nsLookAndFeel.cpp
@@ -1169,18 +1169,19 @@ nsLookAndFeel::EnsureInit()
         if (!allowDarkTheme) {
             g_object_set(settings, dark_setting, FALSE, nullptr);
         }
     }
 
     // Allow content Gtk theme override by pref, it's useful when styled Gtk+
     // widgets break web content.
     if (XRE_IsContentProcess()) {
-        auto contentThemeName =
-            mozilla::Preferences::GetCString("widget.content.gtk-theme-override");
+        nsAutoCString contentThemeName;
+        mozilla::Preferences::GetCString("widget.content.gtk-theme-override",
+                                         contentThemeName);
         if (!contentThemeName.IsEmpty()) {
             g_object_set(settings, "gtk-theme-name", contentThemeName.get(), nullptr);
         }
     }
 
     // Scrollbar colors
     style = ClaimStyleContext(MOZ_GTK_SCROLLBAR_TROUGH_VERTICAL);
     gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
--- a/widget/gtk/nsPSPrinters.cpp
+++ b/widget/gtk/nsPSPrinters.cpp
@@ -84,17 +84,17 @@ nsPSPrinterList::GetPrinterList(nsTArray
     // MOZILLA_POSTSCRIPT_PRINTER_LIST or a preference setting
     // print.printer_list, which contains a space-separated list of printer
     // names.
     aList.AppendElement(
             NS_LITERAL_CSTRING(NS_POSTSCRIPT_DRIVER_NAME "default"));
 
     nsAutoCString list(PR_GetEnv("MOZILLA_POSTSCRIPT_PRINTER_LIST"));
     if (list.IsEmpty()) {
-        list = Preferences::GetCString("print.printer_list");
+        Preferences::GetCString("print.printer_list", list);
     }
     if (!list.IsEmpty()) {
         // For each printer (except "default" which was already added),
         // construct a string "PostScript/<name>" and append it to the list.
         char *state;
 
         for (char *name = PL_strtok_r(list.BeginWriting(), " ", &state);
                 nullptr != name;
--- a/xpcom/threads/BackgroundHangMonitor.cpp
+++ b/xpcom/threads/BackgroundHangMonitor.cpp
@@ -740,20 +740,23 @@ BackgroundHangMonitor::IsDisabled() {
   return BackgroundHangManager::sDisabled;
 #else
   return true;
 #endif
 }
 
 bool
 BackgroundHangMonitor::DisableOnBeta() {
-  nsAdoptingCString clientID = Preferences::GetCString("toolkit.telemetry.cachedClientID");
+  nsAutoCString clientID;
+  nsresult rv =
+    Preferences::GetCString("toolkit.telemetry.cachedClientID", clientID);
   bool telemetryEnabled = Preferences::GetBool("toolkit.telemetry.enabled");
 
-  if (!telemetryEnabled || !clientID || BackgroundHangMonitor::ShouldDisableOnBeta(clientID)) {
+  if (!telemetryEnabled || NS_FAILED(rv) ||
+      BackgroundHangMonitor::ShouldDisableOnBeta(clientID)) {
     if (XRE_IsParentProcess()) {
       BackgroundHangMonitor::Shutdown();
     } else {
       BackgroundHangManager::sDisabled = true;
     }
     return true;
   }
 
--- a/xpfe/appshell/nsAppShellService.cpp
+++ b/xpfe/appshell/nsAppShellService.cpp
@@ -109,19 +109,20 @@ nsAppShellService::EnsurePrivateHiddenWi
 nsresult
 nsAppShellService::CreateHiddenWindowHelper(bool aIsPrivate)
 {
   nsresult rv;
   int32_t initialHeight = 100, initialWidth = 100;
 
 #ifdef XP_MACOSX
   uint32_t    chromeMask = 0;
-  nsAdoptingCString prefVal =
-      Preferences::GetCString("browser.hiddenWindowChromeURL");
-  const char* hiddenWindowURL = prefVal.get() ? prefVal.get() : DEFAULT_HIDDENWINDOW_URL;
+  nsAutoCString prefVal;
+  rv = Preferences::GetCString("browser.hiddenWindowChromeURL", prefVal);
+  const char* hiddenWindowURL =
+    NS_SUCCEEDED(rv) ? prefVal.get() : DEFAULT_HIDDENWINDOW_URL;
   if (aIsPrivate) {
     hiddenWindowURL = DEFAULT_HIDDENWINDOW_URL;
   } else {
     mApplicationProvidedHiddenWindow = prefVal.get() ? true : false;
   }
 #else
   static const char hiddenWindowURL[] = DEFAULT_HIDDENWINDOW_URL;
   uint32_t    chromeMask =  nsIWebBrowserChrome::CHROME_ALL;
--- a/xpfe/appshell/nsXULWindow.cpp
+++ b/xpfe/appshell/nsXULWindow.cpp
@@ -1953,17 +1953,18 @@ NS_IMETHODIMP nsXULWindow::CreateNewCont
 
   // We need to create a new top level window and then enter a nested
   // loop. Eventually the new window will be told that it has loaded,
   // at which time we know it is safe to spin out of the nested loop
   // and allow the opening code to proceed.
 
   nsCOMPtr<nsIURI> uri;
 
-  nsAdoptingCString urlStr = Preferences::GetCString("browser.chromeURL");
+  nsAutoCString urlStr;
+  Preferences::GetCString("browser.chromeURL", urlStr);
   if (urlStr.IsEmpty()) {
     urlStr.AssignLiteral("chrome://navigator/content/navigator.xul");
   }
 
   nsCOMPtr<nsIIOService> service(do_GetService(NS_IOSERVICE_CONTRACTID));
   if (service) {
     service->NewURI(urlStr, nullptr, nullptr, getter_AddRefs(uri));
   }