[libgee] 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: [libgee] gee: Fix memory leak in HashMap.remove and HashSet.remove
- Date: Mon, 1 Jun 2009 16:59:15 -0400 (EDT)
commit 97390ee5198938588e3ebf0281aba15e5d778247
Author: Jürg Billeter <j bitron ch>
Date: Mon Jun 1 22:56:52 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 1c62131..9fa09d3 100644
--- a/gee/hashmap.vala
+++ b/gee/hashmap.vala
@@ -116,9 +116,14 @@ public class Gee.HashMap<K,V> : Object, 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 af23436..d0d0226 100644
--- a/gee/hashset.vala
+++ b/gee/hashset.vala
@@ -102,8 +102,13 @@ public class Gee.HashSet<G> : Object, Iterable<G>, Collection<G>, Set<G> {
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]