зеркало из https://github.com/mozilla/gecko-dev.git
Bug 377423, MemoryElements not removed from the pool properly, fixes topcrash, r=peterv,sr=sicking
This commit is contained in:
Родитель
0a119c5746
Коммит
95dec04fae
|
@ -244,8 +244,7 @@ nsRDFConInstanceTestNode::FilterInstantiations(InstantiationSet& aInstantiations
|
|||
((mContainer == eDontCare) && (mEmpty == empty)))
|
||||
{
|
||||
Element* element =
|
||||
nsRDFConInstanceTestNode::Element::Create(mProcessor->GetPool(),
|
||||
valueres, container, empty);
|
||||
nsRDFConInstanceTestNode::Element::Create(valueres, container, empty);
|
||||
|
||||
if (! element)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
|
|
@ -95,15 +95,15 @@ public:
|
|||
virtual ~Element() { MOZ_COUNT_DTOR(nsRDFConInstanceTestNode::Element); }
|
||||
|
||||
static Element*
|
||||
Create(nsFixedSizeAllocator& aPool, nsIRDFResource* aContainer,
|
||||
Create(nsIRDFResource* aContainer,
|
||||
Test aContainerTest, Test aEmptyTest) {
|
||||
void* place = aPool.Alloc(sizeof(Element));
|
||||
void* place = MemoryElement::gPool.Alloc(sizeof(Element));
|
||||
return place ? ::new (place) Element(aContainer, aContainerTest, aEmptyTest) : nsnull; }
|
||||
|
||||
static void
|
||||
Destroy(nsFixedSizeAllocator& aPool, Element* aElement) {
|
||||
aElement->~Element();
|
||||
aPool.Free(aElement, sizeof(*aElement)); }
|
||||
void Destroy() {
|
||||
this->~Element();
|
||||
MemoryElement::gPool.Free(this, sizeof(Element));
|
||||
}
|
||||
|
||||
virtual const char* Type() const {
|
||||
return "nsRDFConInstanceTestNode::Element"; }
|
||||
|
@ -122,10 +122,6 @@ public:
|
|||
}
|
||||
return PR_FALSE; }
|
||||
|
||||
virtual MemoryElement* Clone(void* aPool) const {
|
||||
return Create(*NS_STATIC_CAST(nsFixedSizeAllocator*, aPool),
|
||||
mContainer, mContainerTest, mEmptyTest); }
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIRDFResource> mContainer;
|
||||
Test mContainerTest;
|
||||
|
|
|
@ -213,8 +213,7 @@ nsRDFConMemberTestNode::FilterInstantiations(InstantiationSet& aInstantiations,
|
|||
if (isconsistent) {
|
||||
// Add a memory element to our set-of-support.
|
||||
Element* element =
|
||||
nsRDFConMemberTestNode::Element::Create(mProcessor->GetPool(),
|
||||
containerRes,
|
||||
nsRDFConMemberTestNode::Element::Create(containerRes,
|
||||
memberValue);
|
||||
|
||||
if (! element)
|
||||
|
@ -269,9 +268,7 @@ nsRDFConMemberTestNode::FilterInstantiations(InstantiationSet& aInstantiations,
|
|||
newinst.AddAssignment(mMemberVariable, node);
|
||||
|
||||
Element* element =
|
||||
nsRDFConMemberTestNode::Element::Create(mProcessor->GetPool(),
|
||||
containerRes,
|
||||
node);
|
||||
nsRDFConMemberTestNode::Element::Create(containerRes, node);
|
||||
|
||||
if (! element)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
@ -361,8 +358,7 @@ nsRDFConMemberTestNode::FilterInstantiations(InstantiationSet& aInstantiations,
|
|||
newinst.AddAssignment(mContainerVariable, source);
|
||||
|
||||
Element* element =
|
||||
nsRDFConMemberTestNode::Element::Create(mProcessor->GetPool(),
|
||||
source,
|
||||
nsRDFConMemberTestNode::Element::Create(source,
|
||||
memberValue);
|
||||
|
||||
if (! element)
|
||||
|
@ -458,14 +454,11 @@ nsRDFConMemberTestNode::FilterInstantiations(InstantiationSet& aInstantiations,
|
|||
Element* element;
|
||||
if (hasContainerBinding) {
|
||||
element =
|
||||
nsRDFConMemberTestNode::Element::Create(mProcessor->GetPool(),
|
||||
containerRes,
|
||||
value);
|
||||
nsRDFConMemberTestNode::Element::Create(containerRes, value);
|
||||
}
|
||||
else {
|
||||
element =
|
||||
nsRDFConMemberTestNode::Element::Create(mProcessor->GetPool(),
|
||||
valueRes, memberValue);
|
||||
nsRDFConMemberTestNode::Element::Create(valueRes, memberValue);
|
||||
}
|
||||
|
||||
if (! element)
|
||||
|
|
|
@ -88,16 +88,14 @@ public:
|
|||
virtual ~Element() { MOZ_COUNT_DTOR(nsRDFConMemberTestNode::Element); }
|
||||
|
||||
static Element*
|
||||
Create(nsFixedSizeAllocator& aPool,
|
||||
nsIRDFResource* aContainer,
|
||||
nsIRDFNode* aMember) {
|
||||
void* place = aPool.Alloc(sizeof(Element));
|
||||
Create(nsIRDFResource* aContainer, nsIRDFNode* aMember) {
|
||||
void* place = MemoryElement::gPool.Alloc(sizeof(Element));
|
||||
return place ? ::new (place) Element(aContainer, aMember) : nsnull; }
|
||||
|
||||
static void
|
||||
Destroy(nsFixedSizeAllocator& aPool, Element* aElement) {
|
||||
aElement->~Element();
|
||||
aPool.Free(aElement, sizeof(*aElement)); }
|
||||
void Destroy() {
|
||||
this->~Element();
|
||||
MemoryElement::gPool.Free(this, sizeof(Element));
|
||||
}
|
||||
|
||||
virtual const char* Type() const {
|
||||
return "nsRDFConMemberTestNode::Element"; }
|
||||
|
@ -113,10 +111,6 @@ public:
|
|||
}
|
||||
return PR_FALSE; }
|
||||
|
||||
virtual MemoryElement* Clone(void* aPool) const {
|
||||
return Create(*NS_STATIC_CAST(nsFixedSizeAllocator*, aPool),
|
||||
mContainer, mMember); }
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIRDFResource> mContainer;
|
||||
nsCOMPtr<nsIRDFNode> mMember;
|
||||
|
|
|
@ -220,8 +220,7 @@ nsRDFPropertyTestNode::FilterInstantiations(InstantiationSet& aInstantiations,
|
|||
if (hasAssertion) {
|
||||
// it's consistent.
|
||||
Element* element =
|
||||
nsRDFPropertyTestNode::Element::Create(mProcessor->GetPool(),
|
||||
sourceRes,
|
||||
nsRDFPropertyTestNode::Element::Create(sourceRes,
|
||||
mProperty,
|
||||
targetValue);
|
||||
|
||||
|
@ -320,8 +319,7 @@ nsRDFPropertyTestNode::FilterInstantiations(InstantiationSet& aInstantiations,
|
|||
newinst.AddAssignment(variable, value);
|
||||
|
||||
Element* element =
|
||||
nsRDFPropertyTestNode::Element::Create(mProcessor->GetPool(),
|
||||
sourceRes,
|
||||
nsRDFPropertyTestNode::Element::Create(sourceRes,
|
||||
mProperty,
|
||||
targetValue);
|
||||
|
||||
|
|
|
@ -109,17 +109,16 @@ public:
|
|||
virtual ~Element() { MOZ_COUNT_DTOR(nsRDFPropertyTestNode::Element); }
|
||||
|
||||
static Element*
|
||||
Create(nsFixedSizeAllocator& aPool,
|
||||
nsIRDFResource* aSource,
|
||||
Create(nsIRDFResource* aSource,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aTarget) {
|
||||
void* place = aPool.Alloc(sizeof(Element));
|
||||
void* place = MemoryElement::gPool.Alloc(sizeof(Element));
|
||||
return place ? ::new (place) Element(aSource, aProperty, aTarget) : nsnull; }
|
||||
|
||||
static void
|
||||
Destroy(nsFixedSizeAllocator& aPool, Element* aElement) {
|
||||
aElement->~Element();
|
||||
aPool.Free(aElement, sizeof(*aElement)); }
|
||||
void Destroy() {
|
||||
this->~Element();
|
||||
MemoryElement::gPool.Free(this, sizeof(Element));
|
||||
}
|
||||
|
||||
virtual const char* Type() const {
|
||||
return "nsRDFPropertyTestNode::Element"; }
|
||||
|
@ -138,10 +137,6 @@ public:
|
|||
}
|
||||
return PR_FALSE; }
|
||||
|
||||
virtual MemoryElement* Clone(void* aPool) const {
|
||||
return Create(*NS_STATIC_CAST(nsFixedSizeAllocator*, aPool),
|
||||
mSource, mProperty, mTarget); }
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIRDFResource> mSource;
|
||||
nsCOMPtr<nsIRDFResource> mProperty;
|
||||
|
|
|
@ -70,6 +70,31 @@ extern PRLogModuleInfo* gXULTemplateLog;
|
|||
|
||||
#include "nsRuleNetwork.h"
|
||||
#include "nsXULTemplateResultSetRDF.h"
|
||||
#include "nsRDFConMemberTestNode.h"
|
||||
#include "nsRDFPropertyTestNode.h"
|
||||
|
||||
PRBool MemoryElement::gPoolInited;
|
||||
nsFixedSizeAllocator MemoryElement::gPool;
|
||||
|
||||
// static
|
||||
PRBool
|
||||
MemoryElement::Init()
|
||||
{
|
||||
if (!gPoolInited) {
|
||||
const size_t bucketsizes[] = {
|
||||
sizeof (nsRDFConMemberTestNode::Element),
|
||||
sizeof (nsRDFPropertyTestNode::Element)
|
||||
};
|
||||
|
||||
if (NS_FAILED(gPool.Init("MemoryElement", bucketsizes,
|
||||
NS_ARRAY_LENGTH(bucketsizes), 256)))
|
||||
return PR_FALSE;
|
||||
|
||||
gPoolInited = PR_TRUE;
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
//
|
||||
|
@ -84,7 +109,7 @@ MemoryElementSet::Add(MemoryElement* aElement)
|
|||
// We've already got this element covered. Since Add()
|
||||
// assumes ownership, and we aren't going to need this,
|
||||
// just nuke it.
|
||||
delete aElement;
|
||||
aElement->Destroy();
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsFixedSizeAllocator.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIDOMNode.h"
|
||||
|
@ -87,14 +88,20 @@ class nsXULTemplateQueryProcessorRDF;
|
|||
* to determine which results will no longer match.
|
||||
*/
|
||||
class MemoryElement {
|
||||
public:
|
||||
protected:
|
||||
MemoryElement() { MOZ_COUNT_CTOR(MemoryElement); }
|
||||
virtual ~MemoryElement() { MOZ_COUNT_DTOR(MemoryElement); }
|
||||
public:
|
||||
|
||||
static PRBool Init();
|
||||
|
||||
static PRBool gPoolInited;
|
||||
static nsFixedSizeAllocator gPool;
|
||||
|
||||
virtual void Destroy() = 0;
|
||||
virtual const char* Type() const = 0;
|
||||
virtual PLHashNumber Hash() const = 0;
|
||||
virtual PRBool Equals(const MemoryElement& aElement) const = 0;
|
||||
virtual MemoryElement* Clone(void* aPool) const = 0;
|
||||
|
||||
PRBool operator==(const MemoryElement& aMemoryElement) const {
|
||||
return Equals(aMemoryElement);
|
||||
|
@ -122,7 +129,7 @@ protected:
|
|||
|
||||
~List() {
|
||||
MOZ_COUNT_DTOR(MemoryElementSet::List);
|
||||
delete mElement;
|
||||
mElement->Destroy();
|
||||
NS_IF_RELEASE(mNext); }
|
||||
|
||||
PRInt32 AddRef() { return ++mRefCnt; }
|
||||
|
|
|
@ -207,7 +207,7 @@ nsXULTemplateQueryProcessorRDF::InitGlobals()
|
|||
&kRDF_type);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
return MemoryElement::Init() ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -236,15 +236,6 @@ nsXULTemplateQueryProcessorRDF::InitializeForBuilding(nsISupports* aDatasource,
|
|||
!mRuleToBindingsMap.Init())
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
const size_t bucketsizes[] = {
|
||||
sizeof (nsRDFConMemberTestNode::Element),
|
||||
sizeof (nsRDFPropertyTestNode::Element)
|
||||
};
|
||||
|
||||
rv = mPool.Init("nsXULTemplateQueryProcessorRDF", bucketsizes, 2, 256);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
mQueryProcessorRDFInited = PR_TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -338,9 +338,6 @@ protected:
|
|||
// the end node of the default simple node hierarchy
|
||||
TestNode* mSimpleRuleMemberTest;
|
||||
|
||||
// fixed size allocator used to allocate rule network structures
|
||||
nsFixedSizeAllocator mPool;
|
||||
|
||||
// the reference variable
|
||||
nsCOMPtr<nsIAtom> mRefVariable;
|
||||
|
||||
|
@ -395,8 +392,6 @@ public:
|
|||
static nsIRDFContainerUtils* gRDFContainerUtils;
|
||||
static nsIRDFResource* kNC_BookmarkSeparator;
|
||||
static nsIRDFResource* kRDF_type;
|
||||
|
||||
nsFixedSizeAllocator& GetPool() { return mPool; }
|
||||
};
|
||||
|
||||
#endif // nsXULTemplateQueryProcessorRDF_h__
|
||||
|
|
Загрузка…
Ссылка в новой задаче