From 64c7a588462683272393e6dd0b6b891a150399b1 Mon Sep 17 00:00:00 2001
From: spog <spog@8a3a26a2-13c4-0310-b231-cf6edde360e5>
Date: Sun, 30 Apr 2006 17:20:57 +0000
Subject: [PATCH] fixed memleak

git-svn-id: https://zerowing.idsoftware.com/svn/radiant/GtkRadiant/trunk@57 8a3a26a2-13c4-0310-b231-cf6edde360e5
---
 CHANGES              |  4 ++++
 libs/signal/signal.h | 28 +++++++++++++++++++++++-----
 2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/CHANGES b/CHANGES
index a7b3a7fd..4c4c2e06 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,10 @@
 This is the changelog for developers, != changelog for the end user 
 that we distribute with the binaries. (see changelog)
 
+30/04/2006
+SPoG
+- Fixed memory leak in signals library.
+
 01/04/2006
 SPoG
 - Added key-observer interface to entity module API.
diff --git a/libs/signal/signal.h b/libs/signal/signal.h
index 77eaa7ce..a4fecd9d 100644
--- a/libs/signal/signal.h
+++ b/libs/signal/signal.h
@@ -108,7 +108,7 @@ namespace ListDetail
   class ListIterator
   {
   public:
-    typedef std::forward_iterator_tag iterator_category;
+    typedef std::bidirectional_iterator_tag iterator_category;
     typedef std::ptrdiff_t difference_type;
     typedef difference_type distance_type;
     typedef typename Traits::value_type value_type;
@@ -197,6 +197,16 @@ class List : private Allocator
   typedef ListDetail::ListNode<Value> Node;
   ListDetail::ListNodeBase list;
   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:
   typedef Value value_type;
   typedef ListDetail::ListIterator< ListDetail::NonConstTraits<Value> > iterator;
@@ -210,6 +220,15 @@ public:
   {
     list_initialise(list);
   }
+  ~List()
+  {
+    for(; list.next != &list;)
+    {
+      Node* node = static_cast<Node*>(list.next);
+      list.next = list.next->next;
+      deleteNode(node);
+    }
+  }
   iterator begin()
   {
     return iterator(static_cast<Node*>(list.next));
@@ -242,9 +261,9 @@ public:
   {
     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());
     return iterator(node);
   }
@@ -253,8 +272,7 @@ public:
     Node* node = pos.node();
     Node* next = node->getNext();
     node_unlink(node);
-    node->~Node();
-    NodeAllocator(*this).deallocate(node, 1);
+    deleteNode(node);
     return iterator(next);
   }
 };
-- 
2.39.5