From e135a755fede81111a89556b4fc5238a198f0a20 Mon Sep 17 00:00:00 2001 From: "hyatt%netscape.com" Date: Sat, 3 Nov 2001 10:24:03 +0000 Subject: [PATCH] Fix leaks that I just introduced. --- content/xul/content/src/nsXULElement.cpp | 50 +++++++++++++----------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index 246c58b98f3c..687c2d714ea8 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -4732,35 +4732,41 @@ nsresult nsXULElement::MakeHeavyweight() nsXULPrototypeElement* proto = mPrototype; mPrototype = nsnull; - if (proto->mNumAttributes == 0) - return NS_OK; + if (proto->mNumAttributes > 0) { + nsXULAttributes *attrs = mSlots->mAttributes; + for (PRInt32 i = 0; i < proto->mNumAttributes; ++i) { + nsXULPrototypeAttribute* protoattr = &(proto->mAttributes[i]); - nsXULAttributes *attrs = mSlots->mAttributes; - for (PRInt32 i = 0; i < proto->mNumAttributes; ++i) { - nsXULPrototypeAttribute* protoattr = &(proto->mAttributes[i]); + // We might have a local value for this attribute, in which case + // we don't want to copy the prototype's value. + // XXXshaver Snapshot the local attrs, so we don't search the ones we + // XXXshaver just appended from the prototype! + if (hadAttributes && FindLocalAttribute(protoattr->mNodeInfo)) + continue; - // We might have a local value for this attribute, in which case - // we don't want to copy the prototype's value. - // XXXshaver Snapshot the local attrs, so we don't search the ones we - // XXXshaver just appended from the prototype! - if (hadAttributes && FindLocalAttribute(protoattr->mNodeInfo)) - continue; + nsAutoString valueStr; + protoattr->mValue.GetValue(valueStr); - nsAutoString valueStr; - protoattr->mValue.GetValue(valueStr); + nsXULAttribute* attr; + rv = nsXULAttribute::Create(NS_STATIC_CAST(nsIStyledContent*, this), + protoattr->mNodeInfo, + valueStr, + &attr); - nsXULAttribute* attr; - rv = nsXULAttribute::Create(NS_STATIC_CAST(nsIStyledContent*, this), - protoattr->mNodeInfo, - valueStr, - &attr); + if (NS_FAILED(rv)) return rv; - if (NS_FAILED(rv)) return rv; - - // transfer ownership of the nsXULAttribute object - attrs->AppendElement(attr); + // transfer ownership of the nsXULAttribute object + attrs->AppendElement(attr); + } } + if (proto->mType == nsXULPrototypeNode::eType_RefCounted_Element) { + proto->mRefCnt--; + if (proto->mRefCnt == 0) + delete proto; + } + + return NS_OK; }