[gxml/gxml-0.20] XDocument: fix memory leak at create_text()
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml/gxml-0.20] XDocument: fix memory leak at create_text()
- Date: Thu, 3 Feb 2022 04:12:18 +0000 (UTC)
commit b59cd4fd57e909a5d81667407f075690033c6355
Author: Daniel Espinosa <esodan gmail com>
Date: Wed Feb 2 18:54:52 2022 -0600
XDocument: fix memory leak at create_text()
Fixed memory leaks for xelement unit tests
gxml/XDocument.vala | 4 +++-
test/XElementTest.vala | 20 ++++++++++----------
2 files changed, 13 insertions(+), 11 deletions(-)
---
diff --git a/gxml/XDocument.vala b/gxml/XDocument.vala
index a59e7bf..ac7d4ad 100644
--- a/gxml/XDocument.vala
+++ b/gxml/XDocument.vala
@@ -140,7 +140,9 @@ public class GXml.XDocument : GXml.XNode,
public GXml.DomNode create_text (string text)
{
var t = doc->new_text (text);
- return new XText (this, t);
+ var n = new XText (this, t);
+ n.take_node ();
+ return n;
}
public override string to_string ()
{
diff --git a/test/XElementTest.vala b/test/XElementTest.vala
index 31546e1..1d5f9db 100644
--- a/test/XElementTest.vala
+++ b/test/XElementTest.vala
@@ -29,16 +29,16 @@ class XElementTest : GLib.Object {
try {
DomDocument doc = new XDocument.from_string ("<root />");
var elem = doc.create_element ("country");
-// var t = doc.create_text_node ("New Zealand");
-// assert (t != null);
-// elem.append_child (t);
-// message ("Elem1:"+elem.write_string ());
-// assert (elem.write_string () == "<country>New Zealand</country>");
-// var elem2 = doc.create_element ("messy");
-// var t2 = doc.create_text_node ("<<>>");
-// elem2.append_child (t2);
-// message ("Elem2:"+elem2.write_string ());
-// assert (elem2.write_string () == "<messy>&lt;<>&gt;</messy>");
+ var t = doc.create_text_node ("New Zealand");
+ assert (t != null);
+ elem.append_child (t);
+ message ("Elem1:"+elem.write_string ());
+ assert (elem.write_string () == "<country>New Zealand</country>");
+ var elem2 = doc.create_element ("messy");
+ var t2 = doc.create_text_node ("<<>>");
+ elem2.append_child (t2);
+ message ("Elem2:"+elem2.write_string ());
+ assert (elem2.write_string () == "<messy>&lt;<>&gt;</messy>");
} catch (GLib.Error e) {
Test.message (e.message);
assert_not_reached ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]