[gxml/gxml-0.20] XNode: fix node child list memory leaks
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml/gxml-0.20] XNode: fix node child list memory leaks
- Date: Thu, 3 Feb 2022 04:12:18 +0000 (UTC)
commit 43b2cf262deaf4c19acb7f2c8b82b7b4fc190f0c
Author: Daniel Espinosa <esodan gmail com>
Date: Wed Feb 2 21:08:11 2022 -0600
XNode: fix node child list memory leaks
gxml/XListChildren.vala | 7 ++++---
gxml/XNode.vala | 14 +++++++++++---
2 files changed, 15 insertions(+), 6 deletions(-)
---
diff --git a/gxml/XListChildren.vala b/gxml/XListChildren.vala
index e7e2ef8..dad55c7 100644
--- a/gxml/XListChildren.vala
+++ b/gxml/XListChildren.vala
@@ -70,6 +70,7 @@ public class GXml.XListChildren : AbstractBidirList<GXml.DomNode>,
public override void insert (int index, GXml.DomNode item) {
var n = @get (index);
if (n == null) return;
+ ((XNode) item).release_node ();
((GXml.XNode) n).get_internal_node ()->add_prev_sibling (((GXml.XNode) item).get_internal_node ());
}
public override Gee.ListIterator<GXml.DomNode> list_iterator () { return new Iterator (_doc, _node); }
@@ -83,8 +84,8 @@ public class GXml.XListChildren : AbstractBidirList<GXml.DomNode>,
if (n == null) return nullnode;
var np = ((GXml.XNode) n).get_internal_node ();
np->unlink ();
- delete np;
- return nullnode;
+ ((GXml.XNode) n).take_node ();
+ return n;
}
/**
* This method is ignored by default.
@@ -131,7 +132,7 @@ public class GXml.XListChildren : AbstractBidirList<GXml.DomNode>,
while (n != null) {
if (n == ((GXml.XNode) item).get_internal_node ()) {
n->unlink ();
- delete n;
+ ((GXml.XNode) item).take_node ();
return true;
}
n = n->next;
diff --git a/gxml/XNode.vala b/gxml/XNode.vala
index 08a88bc..f8f835a 100644
--- a/gxml/XNode.vala
+++ b/gxml/XNode.vala
@@ -419,7 +419,7 @@ public abstract class GXml.XNode : GLib.Object,
//FIXME: Checks for HierarchyRequestError for https://www.w3.org/TR/dom/#concept-node-replace
int i = children_nodes.index_of ((child as GXml.DomNode));
- children_nodes.remove_at (i);
+ var rch = children_nodes.remove_at (i);
if (i < children_nodes.size) {
children_nodes.insert (i, (node as GXml.DomNode));
}
@@ -428,13 +428,21 @@ public abstract class GXml.XNode : GLib.Object,
child_nodes.add (node);
}
+ ((XNode) rch).release_node ();
+ ((XNode) child).take_node ();
+
return child;
}
public DomNode remove_child (DomNode child) throws GLib.Error {
- if (!this.contains (child))
+ if (!this.contains (child)) {
throw new DomError.NOT_FOUND_ERROR (_("Can't find child node to remove or child have a different
parent"));
+ }
+
int i = children_nodes.index_of ((child as GXml.DomNode));
- return (DomNode) children_nodes.remove_at (i);
+ XNode n = (XNode) children_nodes.remove_at (i);
+ n.release_node ();
+ ((XNode) child).take_node ();
+ return child;
}
// DomEventTarget implementation
public void add_event_listener (string type, DomEventListener? callback, bool capture = false)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]