diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp
index a82b7891cc6..7778a9d77ac 100644
--- a/mozilla/content/html/document/src/nsHTMLDocument.cpp
+++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp
@@ -2224,7 +2224,10 @@ nsHTMLDocument::OpenCommon(const nsACString& aContentType, PRBool aReplace)
// Remove all attributes from the root element
while (count-- > 0) {
const nsAttrName* name = root->GetAttrNameAt(count);
- root->UnsetAttr(name->NamespaceID(), name->LocalName(), PR_FALSE);
+ // Hold a strong reference here so that the atom doesn't go away during
+ // UnsetAttr.
+ nsCOMPtr localName = name->LocalName();
+ root->UnsetAttr(name->NamespaceID(), localName, PR_FALSE);
}
// Remove the root from the childlist
diff --git a/mozilla/content/xbl/src/nsXBLBinding.cpp b/mozilla/content/xbl/src/nsXBLBinding.cpp
index c8d28b92df3..5bd699b15a7 100644
--- a/mozilla/content/xbl/src/nsXBLBinding.cpp
+++ b/mozilla/content/xbl/src/nsXBLBinding.cpp
@@ -770,7 +770,9 @@ nsXBLBinding::GenerateAnonymousContent()
const nsAttrName* attrName;
for (PRUint32 i = 0; (attrName = content->GetAttrNameAt(i)); ++i) {
PRInt32 namespaceID = attrName->NamespaceID();
- nsIAtom* name = attrName->LocalName();
+ // Hold a strong reference here so that the atom doesn't go away during
+ // UnsetAttr.
+ nsCOMPtr name = attrName->LocalName();
if (name != nsGkAtoms::includes) {
if (!nsContentUtils::HasNonEmptyAttr(mBoundElement, namespaceID, name)) {
diff --git a/mozilla/content/xbl/src/nsXBLPrototypeBinding.cpp b/mozilla/content/xbl/src/nsXBLPrototypeBinding.cpp
index 672fd5b100b..5d19d29fcc9 100644
--- a/mozilla/content/xbl/src/nsXBLPrototypeBinding.cpp
+++ b/mozilla/content/xbl/src/nsXBLPrototypeBinding.cpp
@@ -570,7 +570,9 @@ nsXBLPrototypeBinding::AttributeChanged(nsIAtom* aAttribute,
element);
if (realElement) {
- nsIAtom* dstAttr = xblAttr->GetDstAttribute();
+ // Hold a strong reference here so that the atom doesn't go away during
+ // UnsetAttr.
+ nsCOMPtr dstAttr = xblAttr->GetDstAttribute();
PRInt32 dstNs = xblAttr->GetDstNameSpace();
if (aRemoveFlag)
diff --git a/mozilla/content/xul/templates/src/nsXULContentBuilder.cpp b/mozilla/content/xul/templates/src/nsXULContentBuilder.cpp
index 15b4f52d351..bc6afeba299 100644
--- a/mozilla/content/xul/templates/src/nsXULContentBuilder.cpp
+++ b/mozilla/content/xul/templates/src/nsXULContentBuilder.cpp
@@ -898,7 +898,9 @@ nsXULContentBuilder::CopyAttributesToElement(nsIContent* aTemplateNode,
for (PRUint32 attr = 0; attr < numAttribs; attr++) {
const nsAttrName* name = aTemplateNode->GetAttrNameAt(attr);
PRInt32 attribNameSpaceID = name->NamespaceID();
- nsIAtom* attribName = name->LocalName();
+ // Hold a strong reference here so that the atom doesn't go away
+ // during UnsetAttr.
+ nsCOMPtr attribName = name->LocalName();
// XXXndeakin ignore namespaces until bug 321182 is fixed
if (attribName != nsGkAtoms::id && attribName != nsGkAtoms::uri) {