Hi Hub,
Why did you remove the initializations for m_pFirst, m_pLast, m_pCache?
Cheers
Martin
________________________________________
From: owner-abisource-cvs-commit@abisource.com
[owner-abisource-cvs-commit@abisource.com] on behalf of
cvs@abisource.com [cvs@abisource.com]
Sent: Sunday, January 08, 2012 2:58 PM
To: abisource-cvs-commit@abisource.com
Subject: hub - r30587 - abiword/trunk/src/text/ptbl/xp
Author: hub
Date: 2012-01-08 04:58:00 +0100 (Sun, 08 Jan 2012)
New Revision: 30587
Modified:
abiword/trunk/src/text/ptbl/xp/pf_Fragments.cpp
abiword/trunk/src/text/ptbl/xp/pf_Fragments.h
abiword/trunk/src/text/ptbl/xp/pt_PT_DeleteStrux.cpp
abiword/trunk/src/text/ptbl/xp/pt_PieceTable.cpp
Log:
Properly purge the fragments maintaining the ownerhsip rules: the PT.
This suppress the leaks.
Add an assert in a place where leakage opens but shouldn't happen.
Make sure Node is not copyable
Modified: abiword/trunk/src/text/ptbl/xp/pf_Fragments.cpp
===================================================================
--- abiword/trunk/src/text/ptbl/xp/pf_Fragments.cpp 2012-01-08
03:57:49 UTC (rev 30586)
+++ abiword/trunk/src/text/ptbl/xp/pf_Fragments.cpp 2012-01-08
03:58:00 UTC (rev 30587)
@@ -83,10 +83,7 @@
//////////////////////////////////////////////
pf_Fragments::pf_Fragments()
- : m_pFirst(0),
- m_pLast(0),
- m_pCache(0),
- m_pLeaf(new Node(Node::black)),
+ : m_pLeaf(new Node(Node::black)),
m_pRoot(m_pLeaf),
m_nSize(0),
m_nDocumentSize(0)
@@ -101,16 +98,14 @@
delete_tree(m_pRoot);
delete m_pLeaf;
+}
- //Comment this out later.
- while (m_pFirst)
- {
- pf_Frag* pNext = m_pFirst->getNext();
- delete m_pFirst;
- m_pFirst = pNext;
+void pf_Fragments::purgeFrags()
+{
+ if (m_pRoot != m_pLeaf) {
+ delete_and_purge_tree(m_pRoot);
}
-
- m_pLast = NULL;
+ m_pRoot = m_pLeaf;
}
void pf_Fragments::appendFrag(pf_Frag * pf)
@@ -1103,6 +1098,21 @@
}
void
+pf_Fragments::delete_and_purge_tree(Node* node)
+{
+ if (node->left != m_pLeaf) {
+ delete_and_purge_tree(node->left);
+ }
+ if (node->right != m_pLeaf) {
+ delete_and_purge_tree(node->right);
+ }
+ if(node->item) {
+ delete node->item;
+ }
+ delete node;
+}
+
+void
pf_Fragments::delete_tree(Node* node)
{
if (node->left != m_pLeaf)
Modified: abiword/trunk/src/text/ptbl/xp/pf_Fragments.h
===================================================================
--- abiword/trunk/src/text/ptbl/xp/pf_Fragments.h 2012-01-08
03:57:49 UTC (rev 30586)
+++ abiword/trunk/src/text/ptbl/xp/pf_Fragments.h 2012-01-08
03:58:00 UTC (rev 30587)
@@ -48,6 +48,8 @@
void insertFrag(pf_Frag *
pfPlace, pf_Frag * pfNew);
void
insertFragBefore(pf_Frag * pfPlace, pf_Frag * pfNew);
void unlinkFrag(pf_Frag * pf);
+ // Call this to purge ALL the fragments. Likely before the destructor.
+ void purgeFrags();
pf_Frag * findFirstFragBeforePos(PT_DocPosition
pos) const;
pf_Frag * getFirst() const;
@@ -61,7 +63,7 @@
{
public:
enum Color { red, black };
- Node(void);
+ Node();
Node(Color c);
Node(Color c, pf_Frag * pf, Node * l, Node * r, Node * p);
~Node(void);
@@ -74,6 +76,10 @@
#ifdef DEBUG
void print(void);
#endif
+ private:
+ // prevent copy
+ Node(const Node&);
+ Node& operator=(const Node&);
};
@@ -135,13 +141,6 @@
private:
- inline pf_Frag* getCache() const { return m_pCache; }
- inline void setCache(pf_Frag* pf)
const { m_pCache = pf; }
-
- pf_Frag * m_pFirst;
- pf_Frag * m_pLast;
- mutable pf_Frag* m_pCache;
-
Iterator insertRoot(pf_Frag* new_piece); // throws
std::bad_alloc (strong)
Iterator insertLeft(pf_Frag* new_piece, Iterator it); //
throws std::bad_alloc (strong)
Iterator insertRight(pf_Frag* new_piece, Iterator it); //
throws std::bad_alloc (strong)
@@ -173,6 +172,9 @@
int _countBlackNodes(const Iterator it) const;
#endif
+ /** will delete the tree AND delete the fragments */
+ void delete_and_purge_tree(Node* node);
+ /** same as above BUT keep the fragments (as we don't own them */
void delete_tree(Node* node);
const Node* _next(const Node* pn) const;
Modified: abiword/trunk/src/text/ptbl/xp/pt_PT_DeleteStrux.cpp
===================================================================
--- abiword/trunk/src/text/ptbl/xp/pt_PT_DeleteStrux.cpp
2012-01-08 03:57:49 UTC (rev 30586)
+++ abiword/trunk/src/text/ptbl/xp/pt_PT_DeleteStrux.cpp
2012-01-08 03:58:00 UTC (rev 30587)
@@ -159,6 +159,8 @@
if(pfsPrev == NULL)
{
_unlinkFrag(pfs,ppfEnd,pfragOffsetEnd);
+ UT_DEBUGMSG(("shoudln't happen."));
+ UT_ASSERT(0);
return false;
}
Modified: abiword/trunk/src/text/ptbl/xp/pt_PieceTable.cpp
===================================================================
--- abiword/trunk/src/text/ptbl/xp/pt_PieceTable.cpp 2012-01-08
03:57:49 UTC (rev 30586)
+++ abiword/trunk/src/text/ptbl/xp/pt_PieceTable.cpp 2012-01-08
03:58:00 UTC (rev 30587)
@@ -65,6 +65,7 @@
pt_PieceTable::~pt_PieceTable()
{
+ m_fragments.purgeFrags();
m_hashStyles.purgeData();
}
-----------------------------------------------
To unsubscribe from this list, send a message to
abisource-cvs-commit-request@abisource.com with the word
unsubscribe in the message body.
Received on Mon Jan 9 00:08:07 2012
This archive was generated by hypermail 2.1.8 : Mon Jan 09 2012 - 00:08:07 CET