Bug 1486690 - Rename NS_str{,}dup and remove unnecessary checks after calls to them. r=glandium
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 28 Aug 2018 15:58:54 +1000
changeset 433689 d6ccf1492e714566c84bb63de3fae0405cc465d9
parent 433688 c330fb64bcd0eb4e8ef98c0389dbd1df19b62b96
child 433690 8257797fd2d80b0954d44d8eebcb33459a9a569a
push id107158
push usernnethercote@mozilla.com
push dateWed, 29 Aug 2018 04:31:19 +0000
treeherdermozilla-inbound@74318e0ebe1e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1486690
milestone63.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 1486690 - Rename NS_str{,}dup and remove unnecessary checks after calls to them. r=glandium The 'x' prefix makes it clearer that these are infallible. A couple of nsJSID methods are now also infallible.
devtools/shared/heapsnapshot/DeserializedNode.cpp
devtools/shared/heapsnapshot/HeapSnapshot.cpp
devtools/shared/heapsnapshot/tests/gtest/DevTools.h
dom/base/NodeUbiReporting.cpp
dom/base/nsDOMWindowUtils.cpp
dom/xbl/nsXBLProtoImplField.cpp
image/imgRequestProxy.cpp
js/src/devtools/rootAnalysis/analyzeHeapWrites.js
js/xpconnect/loader/mozJSComponentLoader.cpp
js/xpconnect/src/XPCComponents.cpp
js/xpconnect/src/XPCJSID.cpp
js/xpconnect/src/XPCJSRuntime.cpp
js/xpconnect/src/xpcprivate.h
layout/style/nsStyleStruct.cpp
layout/style/nsStyleStruct.h
netwerk/base/nsStandardURL.cpp
netwerk/cache/nsCacheEntryDescriptor.cpp
netwerk/cache/nsDiskCacheDeviceSQL.cpp
netwerk/cache2/CacheFile.cpp
netwerk/streamconv/converters/mozTXTToHTMLConv.cpp
toolkit/components/telemetry/Telemetry.cpp
xpcom/base/nsCRTGlue.cpp
xpcom/base/nsCRTGlue.h
xpcom/build/LateWriteChecks.cpp
xpcom/build/XREAppData.h
xpcom/ds/nsHashKeys.h
xpcom/ds/nsVariant.cpp
--- a/devtools/shared/heapsnapshot/DeserializedNode.cpp
+++ b/devtools/shared/heapsnapshot/DeserializedNode.cpp
@@ -82,18 +82,17 @@ class DeserializedEdgeRange : public Edg
   void settle() {
     if (i >= node->edges.length()) {
       front_ = nullptr;
       return;
     }
 
     auto& edge = node->edges[i];
     auto referent = node->getEdgeReferent(edge);
-    currentEdge = Edge(edge.name
-                ? NS_strdup(edge.name) : nullptr, referent);
+    currentEdge = Edge(edge.name ? NS_xstrdup(edge.name) : nullptr, referent);
     front_ = &currentEdge;
   }
 
 public:
   explicit DeserializedEdgeRange(DeserializedNode& node)
     : node(&node)
     , i(0)
   {
--- a/devtools/shared/heapsnapshot/HeapSnapshot.cpp
+++ b/devtools/shared/heapsnapshot/HeapSnapshot.cpp
@@ -142,18 +142,18 @@ struct GetOrInternStringMatcher
 
   explicit GetOrInternStringMatcher(InternedStringSet& strings) : internedStrings(strings) { }
 
   const CharT* match(const std::string* str) {
     MOZ_ASSERT(str);
     size_t length = str->length() / sizeof(CharT);
     auto tempString = reinterpret_cast<const CharT*>(str->data());
 
-    UniqueFreePtr<CharT[]> owned(NS_strndup(tempString, length));
-    if (!owned || !internedStrings.append(std::move(owned)))
+    UniqueFreePtr<CharT[]> owned(NS_xstrndup(tempString, length));
+    if (!internedStrings.append(std::move(owned)))
       return nullptr;
 
     return internedStrings.back().get();
   }
 
   const CharT* match(uint64_t ref) {
     if (MOZ_LIKELY(ref < internedStrings.length())) {
       auto& string = internedStrings[ref];
--- a/devtools/shared/heapsnapshot/tests/gtest/DevTools.h
+++ b/devtools/shared/heapsnapshot/tests/gtest/DevTools.h
@@ -182,18 +182,17 @@ public:
 const char16_t Concrete<FakeNode>::concreteTypeName[] = u"FakeNode";
 
 } // namespace ubi
 } // namespace JS
 
 void AddEdge(FakeNode& node, FakeNode& referent, const char16_t* edgeName = nullptr) {
   char16_t* ownedEdgeName = nullptr;
   if (edgeName) {
-    ownedEdgeName = NS_strdup(edgeName);
-    ASSERT_NE(ownedEdgeName, nullptr);
+    ownedEdgeName = NS_xstrdup(edgeName);
   }
 
   JS::ubi::Edge edge(ownedEdgeName, &referent);
   ASSERT_TRUE(node.edges.append(std::move(edge)));
 }
 
 
 // Custom GMock Matchers
--- a/dom/base/NodeUbiReporting.cpp
+++ b/dom/base/NodeUbiReporting.cpp
@@ -30,26 +30,26 @@ JS::ubi::Concrete<nsINode>::edges(JSCont
   AutoSuppressGCAnalysis suppress;
   auto range = js::MakeUnique<SimpleEdgeRange>();
   if (!range) {
     return nullptr;
   }
   if (get().GetParent()) {
     char16_t* edgeName = nullptr;
     if (wantNames) {
-      edgeName = NS_strdup(u"Parent Node");
+      edgeName = NS_xstrdup(u"Parent Node");
     }
     if (!range->addEdge(JS::ubi::Edge(edgeName, get().GetParent()))) {
       return nullptr;
     }
   }
   for (auto curr = get().GetFirstChild(); curr; curr = curr->GetNextSibling()) {
     char16_t* edgeName = nullptr;
     if (wantNames) {
-      edgeName = NS_strdup(u"Child Node");
+      edgeName = NS_xstrdup(u"Child Node");
     }
     if (!range->addEdge(JS::ubi::Edge(edgeName, curr))) {
       return nullptr;
     }
   }
   return js::UniquePtr<EdgeRange>(range.release());
 }
 
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -2121,18 +2121,17 @@ NS_IMETHODIMP
 nsDOMWindowUtils::GetClassName(JS::Handle<JS::Value> aObject, JSContext* aCx,
                                char** aName)
 {
   // Our argument must be a non-null object.
   if (aObject.isPrimitive()) {
     return NS_ERROR_XPC_BAD_CONVERT_JS;
   }
 
-  *aName = NS_strdup(JS_GetClass(aObject.toObjectOrNull())->name);
-  MOZ_ASSERT(*aName, "NS_strdup should be infallible.");
+  *aName = NS_xstrdup(JS_GetClass(aObject.toObjectOrNull())->name);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::GetVisitedDependentComputedStyle(
                     Element *aElement, const nsAString& aPseudoElement,
                     const nsAString& aPropertyName, nsAString& aResult)
 {
--- a/dom/xbl/nsXBLProtoImplField.cpp
+++ b/dom/xbl/nsXBLProtoImplField.cpp
@@ -29,17 +29,17 @@ using namespace mozilla::dom;
 
 nsXBLProtoImplField::nsXBLProtoImplField(const char16_t* aName, const char16_t* aReadOnly)
   : mNext(nullptr),
     mFieldText(nullptr),
     mFieldTextLength(0),
     mLineNumber(0)
 {
   MOZ_COUNT_CTOR(nsXBLProtoImplField);
-  mName = NS_strdup(aName);  // XXXbz make more sense to use a stringbuffer?
+  mName = NS_xstrdup(aName);  // XXXbz make more sense to use a stringbuffer?
 
   mJSAttributes = JSPROP_ENUMERATE;
   if (aReadOnly) {
     nsAutoString readOnly; readOnly.Assign(aReadOnly);
     if (readOnly.LowerCaseEqualsLiteral("true"))
       mJSAttributes |= JSPROP_READONLY;
   }
 }
--- a/image/imgRequestProxy.cpp
+++ b/image/imgRequestProxy.cpp
@@ -798,17 +798,17 @@ imgRequestProxy::GetMimeType(char** aMim
     return NS_ERROR_FAILURE;
   }
 
   const char* type = GetOwner()->GetMimeType();
   if (!type) {
     return NS_ERROR_FAILURE;
   }
 
-  *aMimeType = NS_strdup(type);
+  *aMimeType = NS_xstrdup(type);
 
   return NS_OK;
 }
 
 imgRequestProxy* imgRequestProxy::NewClonedProxy()
 {
   return new imgRequestProxy();
 }
--- a/js/src/devtools/rootAnalysis/analyzeHeapWrites.js
+++ b/js/src/devtools/rootAnalysis/analyzeHeapWrites.js
@@ -433,17 +433,17 @@ function ignoreContents(entry)
         // These ought to be threadsafe.
         "NS_DebugBreak",
         /mozalloc_handle_oom/,
         /^NS_Log/, /log_print/, /LazyLogModule::operator/,
         /SprintfLiteral/, "PR_smprintf", "PR_smprintf_free",
         /NS_DispatchToMainThread/, /NS_ReleaseOnMainThreadSystemGroup/,
         /NS_NewRunnableFunction/, /NS_Atomize/,
         /nsCSSValue::BufferFromString/,
-        /NS_strdup/,
+        /NS_xstrdup/,
         /Assert_NoQueryNeeded/,
         /AssertCurrentThreadOwnsMe/,
         /PlatformThread::CurrentId/,
         /imgRequestProxy::GetProgressTracker/, // Uses an AutoLock
         /Smprintf/,
         "malloc",
         "calloc",
         "free",
--- a/js/xpconnect/loader/mozJSComponentLoader.cpp
+++ b/js/xpconnect/loader/mozJSComponentLoader.cpp
@@ -1053,32 +1053,32 @@ mozJSComponentLoader::IsModuleLoaded(con
 NS_IMETHODIMP mozJSComponentLoader::LoadedModules(uint32_t* length,
                                                   char*** aModules)
 {
     char** modules = new char*[mImports.Count()];
     *length = mImports.Count();
     *aModules = modules;
 
     for (auto iter = mImports.Iter(); !iter.Done(); iter.Next()) {
-        *modules = NS_strdup(iter.Data()->location);
+        *modules = NS_xstrdup(iter.Data()->location);
         modules++;
     }
 
     return NS_OK;
 }
 
 NS_IMETHODIMP mozJSComponentLoader::LoadedComponents(uint32_t* length,
                                                      char*** aComponents)
 {
     char** comp = new char*[mModules.Count()];
     *length = mModules.Count();
     *aComponents = comp;
 
     for (auto iter = mModules.Iter(); !iter.Done(); iter.Next()) {
-        *comp = NS_strdup(iter.Data()->location);
+        *comp = NS_xstrdup(iter.Data()->location);
         comp++;
     }
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 mozJSComponentLoader::GetModuleImportStack(const nsACString& aLocation,
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -2840,18 +2840,17 @@ nsXPCComponents_Utils::UnwaiveXrays(Hand
 NS_IMETHODIMP
 nsXPCComponents_Utils::GetClassName(HandleValue aObj, bool aUnwrap, JSContext* aCx, char** aRv)
 {
     if (!aObj.isObject())
         return NS_ERROR_INVALID_ARG;
     RootedObject obj(aCx, &aObj.toObject());
     if (aUnwrap)
         obj = js::UncheckedUnwrap(obj, /* stopAtWindowProxy = */ false);
-    *aRv = NS_strdup(js::GetObjectClass(obj)->name);
-    NS_ENSURE_TRUE(*aRv, NS_ERROR_OUT_OF_MEMORY);
+    *aRv = NS_xstrdup(js::GetObjectClass(obj)->name);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsXPCComponents_Utils::GetDOMClassInfo(const nsAString& aClassName,
                                        nsIClassInfo** aClassInfo)
 {
     *aClassInfo = nullptr;
--- a/js/xpconnect/src/XPCJSID.cpp
+++ b/js/xpconnect/src/XPCJSID.cpp
@@ -46,51 +46,50 @@ void nsJSID::Reset()
     if (mNumber && mNumber != gNoString)
         free(mNumber);
     if (mName && mName != gNoString)
         free(mName);
 
     mNumber = mName = nullptr;
 }
 
-bool
+void
 nsJSID::SetName(const char* name)
 {
-    MOZ_ASSERT(!mName || mName == gNoString ,"name already set");
-    MOZ_ASSERT(name,"null name");
-    mName = NS_strdup(name);
-    return mName ? true : false;
+    MOZ_ASSERT(!mName || mName == gNoString, "name already set");
+    MOZ_ASSERT(name, "null name");
+    mName = NS_xstrdup(name);
 }
 
 NS_IMETHODIMP
 nsJSID::GetName(char * *aName)
 {
     if (!aName)
         return NS_ERROR_NULL_POINTER;
 
     if (!NameIsSet())
         SetNameToNoString();
     MOZ_ASSERT(mName, "name not set");
-    *aName = NS_strdup(mName);
-    return *aName ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
+    *aName = NS_xstrdup(mName);
+    return NS_OK;
 }
 
 NS_IMETHODIMP
 nsJSID::GetNumber(char * *aNumber)
 {
     if (!aNumber)
         return NS_ERROR_NULL_POINTER;
 
     if (!mNumber) {
         if (!(mNumber = mID.ToString()))
             mNumber = const_cast<char*>(gNoString);
     }
 
-    *aNumber = NS_strdup(mNumber);
-    return *aNumber ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
+    *aNumber = NS_xstrdup(mNumber);
+    return NS_OK;
 }
 
 NS_IMETHODIMP_(const nsID*)
 nsJSID::GetID()
 {
     return &mID;
 }
 
@@ -135,23 +134,23 @@ nsJSID::Initialize(const char* idString)
 
             // error - reset to invalid state
             mID = GetInvalidIID();
         }
     }
     return NS_ERROR_FAILURE;
 }
 
-bool
+void
 nsJSID::InitWithName(const nsID& id, const char* nameString)
 {
     MOZ_ASSERT(nameString, "no name");
     Reset();
     mID = id;
-    return SetName(nameString);
+    SetName(nameString);
 }
 
 // try to use the name, if no name, then use the number
 NS_IMETHODIMP
 nsJSID::ToString(char** _retval)
 {
     if (mName && mName != gNoString)
         return GetName(_retval);
@@ -563,20 +562,18 @@ nsJSCID::Initialize(const char* str)
     } else {
         nsCOMPtr<nsIComponentRegistrar> registrar;
         NS_GetComponentRegistrar(getter_AddRefs(registrar));
         NS_ENSURE_TRUE(registrar, NS_ERROR_FAILURE);
 
         nsCID* cid;
         if (NS_FAILED(registrar->ContractIDToCID(str, &cid)))
             return NS_ERROR_FAILURE;
-        bool success = mDetails->InitWithName(*cid, str);
+        mDetails->InitWithName(*cid, str);
         free(cid);
-        if (!success)
-            return NS_ERROR_FAILURE;
     }
     return NS_OK;
 }
 
 NS_IMETHODIMP nsJSCID::ToString(char** _retval)
     {ResolveName(); return mDetails->ToString(_retval);}
 
 void
--- a/js/xpconnect/src/XPCJSRuntime.cpp
+++ b/js/xpconnect/src/XPCJSRuntime.cpp
@@ -2897,17 +2897,17 @@ ReflectorNode::edges(JSContext* cx, bool
     // that to guard against uninitialized objects.
     nsISupports* supp = UnwrapDOMObjectToISupports(&get());
     if (supp) {
         nsCOMPtr<nsINode> node;
         UNWRAP_OBJECT(Node, &get(), node);
         if (node) {
             char16_t* edgeName = nullptr;
             if (wantNames) {
-                edgeName = NS_strdup(u"Reflected Node");
+                edgeName = NS_xstrdup(u"Reflected Node");
             }
             if (!range->addEdge(Edge(edgeName, node.get()))){
                 return nullptr;
             }
         }
     }
     return js::UniquePtr<EdgeRange>(range.release());
 }
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -2120,18 +2120,18 @@ extern void xpc_DestroyJSxIDClassObjects
 class nsJSID final : public nsIJSID
 {
 public:
     NS_DEFINE_STATIC_CID_ACCESSOR(NS_JS_ID_CID)
 
     NS_DECL_ISUPPORTS
     NS_DECL_NSIJSID
 
-    bool InitWithName(const nsID& id, const char* nameString);
-    bool SetName(const char* name);
+    void InitWithName(const nsID& id, const char* nameString);
+    void SetName(const char* name);
     void   SetNameToNoString()
         {MOZ_ASSERT(!mName, "name already set"); mName = const_cast<char*>(gNoString);}
     bool NameIsSet() const {return nullptr != mName;}
     const nsID& ID() const {return mID;}
     bool IsValid() const {return !mID.Equals(GetInvalidIID());}
 
     static already_AddRefed<nsJSID> NewID(const char* str);
     static already_AddRefed<nsJSID> NewID(const nsID& id);
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -4187,17 +4187,17 @@ nsStyleContentData::nsStyleContentData(c
     case StyleContentType::Counters:
       mContent.mCounters = aOther.mContent.mCounters;
       mContent.mCounters->AddRef();
       break;
     case StyleContentType::Attr:
       mContent.mAttr = new nsStyleContentAttr(*aOther.mContent.mAttr);
       break;
     case StyleContentType::String:
-      mContent.mString = NS_strdup(aOther.mContent.mString);
+      mContent.mString = NS_xstrdup(aOther.mContent.mString);
       break;
     default:
       MOZ_ASSERT(!aOther.mContent.mString);
       mContent.mString = nullptr;
   }
 }
 
 bool
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -2672,17 +2672,17 @@ public:
 
   void SetString(StyleContentType aType, const char16_t* aString)
   {
     MOZ_ASSERT(aType == StyleContentType::String);
     MOZ_ASSERT(aString);
     MOZ_ASSERT(mType == StyleContentType::Uninitialized,
                "should only initialize nsStyleContentData once");
     mType = aType;
-    mContent.mString = NS_strdup(aString);
+    mContent.mString = NS_xstrdup(aString);
   }
 
   void SetCounters(StyleContentType aType,
                    already_AddRefed<CounterFunction> aCounterFunction)
   {
     MOZ_ASSERT(aType == StyleContentType::Counter ||
                aType == StyleContentType::Counters);
     MOZ_ASSERT(mType == StyleContentType::Uninitialized,
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -2420,28 +2420,28 @@ nsStandardURL::Resolve(const nsACString 
         // this URL appears to be absolute
         // but try to find out more
         if (SegmentIs(mScheme, relpath, scheme, true)) {
             // mScheme and Scheme are the same
             // but this can still be relative
             if (strncmp(relpath + scheme.mPos + scheme.mLen, "://", 3) == 0) {
                 // now this is really absolute
                 // because a :// follows the scheme
-                result = NS_strdup(relpath);
+                result = NS_xstrdup(relpath);
             } else {
                 // This is a deprecated form of relative urls like
                 // http:file or http:/path/file
                 // we will support it for now ...
                 relative = true;
                 offset = scheme.mLen + 1;
             }
         } else {
             // the schemes are not the same, we are also done
             // because we have to assume this is absolute
-            result = NS_strdup(relpath);
+            result = NS_xstrdup(relpath);
         }
     } else {
         // add some flags to coalesceFlag if it is an ftp-url
         // need this later on when coalescing the resulting URL
         if (SegmentIs(mScheme,"ftp")) {
             coalesceFlag = (netCoalesceFlags) (coalesceFlag
                                         | NET_COALESCE_ALLOW_RELATIVE_ROOT
                                         | NET_COALESCE_DOUBLE_SLASH_IS_ROOT);
--- a/netwerk/cache/nsCacheEntryDescriptor.cpp
+++ b/netwerk/cache/nsCacheEntryDescriptor.cpp
@@ -606,18 +606,17 @@ nsCacheEntryDescriptor::GetMetaDataEleme
     nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETMETADATAELEMENT));
     NS_ENSURE_TRUE(mCacheEntry, NS_ERROR_NOT_AVAILABLE);
 
     const char *value;
 
     value = mCacheEntry->GetMetaDataElement(key);
     if (!value) return NS_ERROR_NOT_AVAILABLE;
 
-    *result = NS_strdup(value);
-    if (!*result) return NS_ERROR_OUT_OF_MEMORY;
+    *result = NS_xstrdup(value);
 
     return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsCacheEntryDescriptor::SetMetaDataElement(const char *key, const char *value)
 {
--- a/netwerk/cache/nsDiskCacheDeviceSQL.cpp
+++ b/netwerk/cache/nsDiskCacheDeviceSQL.cpp
@@ -2339,21 +2339,17 @@ nsOfflineCacheDevice::RunSimpleQuery(moz
     rv = statement->ExecuteStep(&hasRows);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   *count = valArray.Length();
   char **ret = static_cast<char **>(moz_xmalloc(*count * sizeof(char*)));
 
   for (uint32_t i = 0; i <  *count; i++) {
-    ret[i] = NS_strdup(valArray[i].get());
-    if (!ret[i]) {
-      NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(i, ret);
-      return NS_ERROR_OUT_OF_MEMORY;
-    }
+    ret[i] = NS_xstrdup(valArray[i].get());
   }
 
   *values = ret;
 
   return NS_OK;
 }
 
 nsresult
--- a/netwerk/cache2/CacheFile.cpp
+++ b/netwerk/cache2/CacheFile.cpp
@@ -1132,17 +1132,17 @@ CacheFile::GetElement(const char *aKey, 
   MOZ_ASSERT(mMetadata);
   NS_ENSURE_TRUE(mMetadata, NS_ERROR_UNEXPECTED);
 
   const char *value;
   value = mMetadata->GetElement(aKey);
   if (!value)
     return NS_ERROR_NOT_AVAILABLE;
 
-  *_retval = NS_strdup(value);
+  *_retval = NS_xstrdup(value);
   return NS_OK;
 }
 
 nsresult
 CacheFile::SetElement(const char *aKey, const char *aValue)
 {
   CacheFileAutoLock lock(this);
 
--- a/netwerk/streamconv/converters/mozTXTToHTMLConv.cpp
+++ b/netwerk/streamconv/converters/mozTXTToHTMLConv.cpp
@@ -1366,17 +1366,17 @@ mozTXTToHTMLConv::ScanTXT(const char16_t
   // FIX ME!!!
   nsString outString;
   int32_t inLength = NS_strlen(text);
   // by setting a large capacity up front, we save time
   // when appending characters to the output string because we don't
   // need to reallocate and re-copy the characters already in the out String.
   NS_ASSERTION(inLength, "ScanTXT passed 0 length string");
   if (inLength == 0) {
-    *_retval = NS_strdup(text);
+    *_retval = NS_xstrdup(text);
     return NS_OK;
   }
 
   outString.SetCapacity(uint32_t(inLength * growthRate));
   ScanTXT(text, inLength, whattodo, outString);
 
   *_retval = ToNewUnicode(outString);
   return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
--- a/toolkit/components/telemetry/Telemetry.cpp
+++ b/toolkit/components/telemetry/Telemetry.cpp
@@ -424,17 +424,17 @@ GetShutdownTimeFileName()
   if (!gRecordedShutdownTimeFileName) {
     nsCOMPtr<nsIFile> mozFile;
     NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(mozFile));
     if (!mozFile)
       return nullptr;
 
     mozFile->AppendNative(NS_LITERAL_CSTRING("Telemetry.ShutdownTime.txt"));
 
-    gRecordedShutdownTimeFileName = NS_strdup(mozFile->NativePath().get());
+    gRecordedShutdownTimeFileName = NS_xstrdup(mozFile->NativePath().get());
   }
 
   return gRecordedShutdownTimeFileName;
 }
 
 NS_IMETHODIMP
 TelemetryImpl::GetLastShutdownDuration(uint32_t *aResult)
 {
--- a/xpcom/base/nsCRTGlue.cpp
+++ b/xpcom/base/nsCRTGlue.cpp
@@ -116,37 +116,37 @@ NS_strncmp(const char16_t* aStrA, const 
     ++aStrB;
     --aLen;
   }
 
   return aLen ? *aStrA != '\0' : 0;
 }
 
 char16_t*
-NS_strdup(const char16_t* aString)
+NS_xstrdup(const char16_t* aString)
 {
   uint32_t len = NS_strlen(aString);
-  return NS_strndup(aString, len);
+  return NS_xstrndup(aString, len);
 }
 
 template<typename CharT>
 CharT*
-NS_strndup(const CharT* aString, uint32_t aLen)
+NS_xstrndup(const CharT* aString, uint32_t aLen)
 {
   auto newBuf = (CharT*)moz_xmalloc((aLen + 1) * sizeof(CharT));
   memcpy(newBuf, aString, aLen * sizeof(CharT));
   newBuf[aLen] = '\0';
   return newBuf;
 }
 
-template char16_t* NS_strndup<char16_t>(const char16_t* aString, uint32_t aLen);
-template char* NS_strndup<char>(const char* aString, uint32_t aLen);
+template char16_t* NS_xstrndup<char16_t>(const char16_t* aString, uint32_t aLen);
+template char* NS_xstrndup<char>(const char* aString, uint32_t aLen);
 
 char*
-NS_strdup(const char* aString)
+NS_xstrdup(const char* aString)
 {
   uint32_t len = strlen(aString);
   char* str = (char*)moz_xmalloc(len + 1);
   memcpy(str, aString, len);
   str[len] = '\0';
   return str;
 }
 
--- a/xpcom/base/nsCRTGlue.h
+++ b/xpcom/base/nsCRTGlue.h
@@ -50,32 +50,32 @@ int NS_strcmp(const char16_t* aStrA, con
 /**
  * "strncmp" for char16_t strings
  */
 int NS_strncmp(const char16_t* aStrA, const char16_t* aStrB, size_t aLen);
 
 /**
  * "strdup" for char16_t strings, uses the infallible moz_xmalloc allocator.
  */
-char16_t* NS_strdup(const char16_t* aString);
+char16_t* NS_xstrdup(const char16_t* aString);
 
 /**
  * "strdup", but using the infallible moz_xmalloc allocator.
  */
-char* NS_strdup(const char* aString);
+char* NS_xstrdup(const char* aString);
 
 /**
  * strndup for char16_t or char strings (normal strndup is not available on
  * windows). This function will ensure that the new string is
  * null-terminated. Uses the infallible moz_xmalloc allocator.
  *
  * CharT may be either char16_t or char.
  */
 template<typename CharT>
-CharT* NS_strndup(const CharT* aString, uint32_t aLen);
+CharT* NS_xstrndup(const CharT* aString, uint32_t aLen);
 
 // The following case-conversion methods only deal in the ascii repertoire
 // A-Z and a-z
 
 // semi-private data declarations... don't use these directly.
 class nsLowerUpperUtils
 {
 public:
--- a/xpcom/build/LateWriteChecks.cpp
+++ b/xpcom/build/LateWriteChecks.cpp
@@ -90,17 +90,17 @@ RecordStackWalker(uint32_t aFrameNumber,
  * An implementation of IOInterposeObserver to be registered with IOInterposer.
  * This observer logs all writes as late writes.
  */
 class LateWriteObserver final : public IOInterposeObserver
 {
   using char_type = filesystem::Path::value_type;
 public:
   explicit LateWriteObserver(const char_type* aProfileDirectory)
-    : mProfileDirectory(NS_strdup(aProfileDirectory))
+    : mProfileDirectory(NS_xstrdup(aProfileDirectory))
   {
   }
   ~LateWriteObserver()
   {
     free(mProfileDirectory);
     mProfileDirectory = nullptr;
   }
 
--- a/xpcom/build/XREAppData.h
+++ b/xpcom/build/XREAppData.h
@@ -62,17 +62,17 @@ public:
       *this = v;
     }
     CharPtr(CharPtr&&) = default;
     ~CharPtr() = default;
 
     CharPtr& operator=(const char* v)
     {
       if (v) {
-        mValue.reset(NS_strdup(v));
+        mValue.reset(NS_xstrdup(v));
       } else {
         mValue = nullptr;
       }
       return *this;
     }
     CharPtr& operator=(const CharPtr& v)
     {
       *this = (const char*) v;
--- a/xpcom/ds/nsHashKeys.h
+++ b/xpcom/ds/nsHashKeys.h
@@ -594,19 +594,19 @@ private:
  * the string lives longer than the hash table.
  */
 class nsUnicharPtrHashKey : public PLDHashEntryHdr
 {
 public:
   typedef const char16_t* KeyType;
   typedef const char16_t* KeyTypePointer;
 
-  explicit nsUnicharPtrHashKey(const char16_t* aKey) : mKey(NS_strdup(aKey)) {}
+  explicit nsUnicharPtrHashKey(const char16_t* aKey) : mKey(NS_xstrdup(aKey)) {}
   nsUnicharPtrHashKey(const nsUnicharPtrHashKey& aToCopy)
-    : mKey(NS_strdup(aToCopy.mKey))
+    : mKey(NS_xstrdup(aToCopy.mKey))
   {
   }
 
   nsUnicharPtrHashKey(nsUnicharPtrHashKey&& aOther)
     : mKey(aOther.mKey)
   {
     aOther.mKey = nullptr;
   }
--- a/xpcom/ds/nsVariant.cpp
+++ b/xpcom/ds/nsVariant.cpp
@@ -396,17 +396,17 @@ CloneArray(uint16_t aInType, const nsIID
     }
 
     case nsIDataType::VTYPE_WCHAR_STR: {
       char16_t** inp  = (char16_t**)aInValue;
       char16_t** outp = (char16_t**)*aOutValue;
       for (i = aInCount; i > 0; i--) {
         char16_t* str = *(inp++);
         if (str) {
-          *(outp++) = NS_strdup(str);
+          *(outp++) = NS_xstrdup(str);
         } else {
           *(outp++) = nullptr;
         }
       }
       break;
     }
 
     // The rest are illegal.