summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKulanthaivel Palanichamy <kulanthaivel@codeaurora.org>2012-11-27 11:50:21 -0800
committerSteve Kondik <shade@chemlab.org>2013-01-21 01:19:49 -0800
commit68e9c4e7cda8607f395a75781809fabbcc2bbeb8 (patch)
treef0821a7c1d6f2f4e1b38ec045efa5f875c7b8a02
parent4bb8cc2e30240dd477bdb3fa20c16c9208ad7292 (diff)
downloadexternal_webkit-68e9c4e7cda8607f395a75781809fabbcc2bbeb8.zip
external_webkit-68e9c4e7cda8607f395a75781809fabbcc2bbeb8.tar.gz
external_webkit-68e9c4e7cda8607f395a75781809fabbcc2bbeb8.tar.bz2
[WebKit] Fix for the memory leak
Memory leak was introduced by "DOM traversal optimizations DOM Core optimizations Prefetch optimization for DOM Tree Traversal" Cachelist was being mismanaged. Removing it. Change-Id: I8abb2b6b30b1fbeb931a19be3567c78c3f697d77
-rw-r--r--Source/WebCore/dom/ChildNodeList.cpp17
-rw-r--r--Source/WebCore/dom/ChildNodeList.h8
-rw-r--r--Source/WebCore/dom/Node.cpp21
-rw-r--r--Source/WebCore/dom/Node.h1
-rw-r--r--Source/WebCore/dom/NodeRareData.h6
5 files changed, 11 insertions, 42 deletions
diff --git a/Source/WebCore/dom/ChildNodeList.cpp b/Source/WebCore/dom/ChildNodeList.cpp
index 253537c..3328c7c 100644
--- a/Source/WebCore/dom/ChildNodeList.cpp
+++ b/Source/WebCore/dom/ChildNodeList.cpp
@@ -27,27 +27,19 @@
namespace WebCore {
-ChildNodeList::ChildNodeList(PassRefPtr<Node> rootNode)
- : DynamicNodeList(rootNode)
+ChildNodeList::ChildNodeList(PassRefPtr<Node> rootNode, DynamicNodeList::Caches* info)
+ : DynamicNodeList(rootNode, info)
{
}
-ChildNodeList::~ChildNodeList()
-{
- m_rootNode->removeCachedChildNodeList(this);
-}
-
unsigned ChildNodeList::length() const
{
if (m_caches->isLengthCacheValid)
return m_caches->cachedLength;
unsigned len = 0;
- Vector<Node* >& cachedNodes = m_caches->cachedNodes;
- for (Node* n = m_rootNode->firstChild(); n; n = n->nextSibling()) {
- cachedNodes.append(n);
+ for (Node* n = m_rootNode->firstChild(); n; n = n->nextSibling())
len++;
- }
m_caches->cachedLength = len;
m_caches->isLengthCacheValid = true;
@@ -57,9 +49,6 @@ unsigned ChildNodeList::length() const
Node* ChildNodeList::item(unsigned index) const
{
- if (m_caches->isLengthCacheValid && index < m_caches->cachedLength)
- return m_caches->cachedNodes[index];
-
unsigned int pos = 0;
Node* n = m_rootNode->firstChild();
diff --git a/Source/WebCore/dom/ChildNodeList.h b/Source/WebCore/dom/ChildNodeList.h
index df3d67b..f38106d 100644
--- a/Source/WebCore/dom/ChildNodeList.h
+++ b/Source/WebCore/dom/ChildNodeList.h
@@ -31,18 +31,16 @@ namespace WebCore {
class ChildNodeList : public DynamicNodeList {
public:
- static PassRefPtr<ChildNodeList> create(PassRefPtr<Node> rootNode)
+ static PassRefPtr<ChildNodeList> create(PassRefPtr<Node> rootNode, Caches* caches)
{
- return adoptRef(new ChildNodeList(rootNode));
+ return adoptRef(new ChildNodeList(rootNode, caches));
}
- virtual ~ChildNodeList();
-
virtual unsigned length() const;
virtual Node* item(unsigned index) const;
protected:
- ChildNodeList(PassRefPtr<Node> rootNode);
+ ChildNodeList(PassRefPtr<Node> rootNode, Caches*);
virtual bool nodeMatches(Element*) const;
};
diff --git a/Source/WebCore/dom/Node.cpp b/Source/WebCore/dom/Node.cpp
index 5b173bf..facb694 100644
--- a/Source/WebCore/dom/Node.cpp
+++ b/Source/WebCore/dom/Node.cpp
@@ -628,12 +628,8 @@ void Node::setNodeValue(const String& /*nodeValue*/, ExceptionCode& ec)
PassRefPtr<NodeList> Node::childNodes()
{
NodeListsNodeData* data = ensureRareData()->ensureNodeLists(this);
- if (data->m_childNodeListCache)
- return PassRefPtr<ChildNodeList>(data->m_childNodeListCache);
- RefPtr<ChildNodeList> childNodeList = ChildNodeList::create(this);
- data->m_childNodeListCache = childNodeList.get();
- return childNodeList.release();
+ return ChildNodeList::create(this, data->m_childNodeListCaches.get());
}
Node *Node::lastDescendant() const
@@ -1149,16 +1145,6 @@ void Node::removeCachedLabelsNodeList(DynamicNodeList* list)
data->m_labelsNodeListCache = 0;
}
-void Node::removeCachedChildNodeList(DynamicNodeList* list)
-{
- ASSERT(rareData());
- ASSERT(rareData()->nodeLists());
- ASSERT_UNUSED(list, list->hasOwnCaches());
-
- NodeListsNodeData* data = rareData()->nodeLists();
- data->m_childNodeListCache = 0;
-}
-
Node* Node::traverseNextNode(const Node* stayWithin) const
{
prefetchTarget();
@@ -2504,8 +2490,7 @@ void Node::formatForDebugger(char* buffer, unsigned length) const
void NodeListsNodeData::invalidateCaches()
{
- if (m_childNodeListCache)
- m_childNodeListCache->invalidateCache();
+ m_childNodeListCaches->reset();
if (m_labelsNodeListCache)
m_labelsNodeListCache->invalidateCache();
@@ -2536,7 +2521,7 @@ bool NodeListsNodeData::isEmpty() const
if (!m_listsWithCaches.isEmpty())
return false;
- if (m_childNodeListCache)
+ if (m_childNodeListCaches->refCount())
return false;
TagNodeListCacheNS::const_iterator tagCacheEndNS = m_tagNodeListCacheNS.end();
diff --git a/Source/WebCore/dom/Node.h b/Source/WebCore/dom/Node.h
index ad5ee9d..d75d064 100644
--- a/Source/WebCore/dom/Node.h
+++ b/Source/WebCore/dom/Node.h
@@ -563,7 +563,6 @@ public:
void removeCachedTagNodeList(TagNodeList*, const AtomicString&);
void removeCachedTagNodeListNS(TagNodeListNS*, const QualifiedName&);
void removeCachedLabelsNodeList(DynamicNodeList*);
- void removeCachedChildNodeList(DynamicNodeList*);
PassRefPtr<NodeList> getElementsByTagName(const AtomicString&);
PassRefPtr<NodeList> getElementsByTagNameNS(const AtomicString& namespaceURI, const AtomicString& localName);
diff --git a/Source/WebCore/dom/NodeRareData.h b/Source/WebCore/dom/NodeRareData.h
index b81dd3f..7bbd0c1 100644
--- a/Source/WebCore/dom/NodeRareData.h
+++ b/Source/WebCore/dom/NodeRareData.h
@@ -22,7 +22,6 @@
#ifndef NodeRareData_h
#define NodeRareData_h
-#include "ChildNodeList.h"
#include "ClassNodeList.h"
#include "DynamicNodeList.h"
#include "NameNodeList.h"
@@ -43,7 +42,7 @@ public:
typedef HashSet<DynamicNodeList*> NodeListSet;
NodeListSet m_listsWithCaches;
- RefPtr<ChildNodeList> m_childNodeListCache;
+ RefPtr<DynamicNodeList::Caches> m_childNodeListCaches;
typedef HashMap<String, ClassNodeList*> ClassNodeListCache;
ClassNodeListCache m_classNodeListCache;
@@ -70,8 +69,7 @@ public:
private:
NodeListsNodeData()
- : m_childNodeListCache(0)
- , m_labelsNodeListCache(0)
+ : m_childNodeListCaches(DynamicNodeList::Caches::create()), m_labelsNodeListCache(0)
{
}
};