[vala] gee: Fix memory leak in HashMap.remove and HashSet.remove
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Subject: [vala] gee: Fix memory leak in HashMap.remove and HashSet.remove
- Date: Mon, 1 Jun 2009 16:59:17 -0400 (EDT)
commit 0f54f1d182d262f6b328642de4507c7ec900c2b6
Author: Jürg Billeter <j bitron ch>
Date: Mon Jun 1 22:53:34 2009 +0200
gee: Fix memory leak in HashMap.remove and HashSet.remove
Fixes bug 584440.
---
gee/hashmap.vala | 7 ++++++-
gee/hashset.vala | 7 ++++++-
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/gee/hashmap.vala b/gee/hashmap.vala
index 740c409..67b08ba 100644
--- a/gee/hashmap.vala
+++ b/gee/hashmap.vala
@@ -113,9 +113,14 @@ public class Gee.HashMap<K,V> : CollectionObject, Map<K,V> {
public bool remove (K key) {
Node<K,V>** node = lookup_node (key);
if (*node != null) {
+ Node<K,V> next = (owned) (*node)->next;
+
(*node)->key = null;
(*node)->value = null;
- *node = (*node)->next;
+ delete *node;
+
+ *node = (owned) next;
+
_nnodes--;
resize ();
_stamp++;
diff --git a/gee/hashset.vala b/gee/hashset.vala
index f042e76..a5a9805 100644
--- a/gee/hashset.vala
+++ b/gee/hashset.vala
@@ -99,8 +99,13 @@ public class Gee.HashSet<G> : CollectionObject, Iterable<G>, Collection<G>, Set<
public bool remove (G key) {
Node<G>** node = lookup_node (key);
if (*node != null) {
+ Node<G> next = (owned) (*node)->next;
+
(*node)->key = null;
- *node = (*node)->next;
+ delete *node;
+
+ *node = (owned) next;
+
_nnodes--;
resize ();
_stamp++;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]