fixed memleak

git-svn-id: svn://svn.icculus.org/gtkradiant/GtkRadiant/trunk@57 8a3a26a2-13c4-0310-b231-cf6edde360e5
This commit is contained in:
spog 2006-04-30 17:20:57 +00:00
parent 55ceebf861
commit d617f066bc
2 changed files with 27 additions and 5 deletions

View file

@ -1,6 +1,10 @@
This is the changelog for developers, != changelog for the end user This is the changelog for developers, != changelog for the end user
that we distribute with the binaries. (see changelog) that we distribute with the binaries. (see changelog)
30/04/2006
SPoG
- Fixed memory leak in signals library.
01/04/2006 01/04/2006
SPoG SPoG
- Added key-observer interface to entity module API. - Added key-observer interface to entity module API.

View file

@ -108,7 +108,7 @@ namespace ListDetail
class ListIterator class ListIterator
{ {
public: public:
typedef std::forward_iterator_tag iterator_category; typedef std::bidirectional_iterator_tag iterator_category;
typedef std::ptrdiff_t difference_type; typedef std::ptrdiff_t difference_type;
typedef difference_type distance_type; typedef difference_type distance_type;
typedef typename Traits::value_type value_type; typedef typename Traits::value_type value_type;
@ -197,6 +197,16 @@ class List : private Allocator
typedef ListDetail::ListNode<Value> Node; typedef ListDetail::ListNode<Value> Node;
ListDetail::ListNodeBase list; ListDetail::ListNodeBase list;
typedef typename Allocator::template rebind<Node>::other NodeAllocator; typedef typename Allocator::template rebind<Node>::other NodeAllocator;
Node* newNode(const Value& value)
{
return new (NodeAllocator(*this).allocate(1)) Node(value);
}
void deleteNode(Node* node)
{
node->~Node();
NodeAllocator(*this).deallocate(node, 1);
}
public: public:
typedef Value value_type; typedef Value value_type;
typedef ListDetail::ListIterator< ListDetail::NonConstTraits<Value> > iterator; typedef ListDetail::ListIterator< ListDetail::NonConstTraits<Value> > iterator;
@ -210,6 +220,15 @@ public:
{ {
list_initialise(list); list_initialise(list);
} }
~List()
{
for(; list.next != &list;)
{
Node* node = static_cast<Node*>(list.next);
list.next = list.next->next;
deleteNode(node);
}
}
iterator begin() iterator begin()
{ {
return iterator(static_cast<Node*>(list.next)); return iterator(static_cast<Node*>(list.next));
@ -242,9 +261,9 @@ public:
{ {
erase(begin(), value); erase(begin(), value);
} }
iterator insert(iterator pos, const Value& x) iterator insert(iterator pos, const Value& value)
{ {
Node* node = new (NodeAllocator(*this).allocate(1)) Node(x); Node* node = newNode(value);
node_link(node, pos.node()); node_link(node, pos.node());
return iterator(node); return iterator(node);
} }
@ -253,8 +272,7 @@ public:
Node* node = pos.node(); Node* node = pos.node();
Node* next = node->getNext(); Node* next = node->getNext();
node_unlink(node); node_unlink(node);
node->~Node(); deleteNode(node);
NodeAllocator(*this).deallocate(node, 1);
return iterator(next); return iterator(next);
} }
}; };