[gxml] XPath: fix memory leaks
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] XPath: fix memory leaks
- Date: Thu, 3 Feb 2022 03:26:47 +0000 (UTC)
commit 6acd13dfd4f503d392beb32312d38d48fb87ac56
Author: Daniel Espinosa <esodan gmail com>
Date: Wed Feb 2 21:26:15 2022 -0600
XPath: fix memory leaks
gxml/LXPathObject.vala | 37 ++++++++++++++++++++++++++-----------
gxml/XDocument.vala | 9 ++++++++-
2 files changed, 34 insertions(+), 12 deletions(-)
---
diff --git a/gxml/LXPathObject.vala b/gxml/LXPathObject.vala
index faa425b..f94b5d0 100644
--- a/gxml/LXPathObject.vala
+++ b/gxml/LXPathObject.vala
@@ -22,27 +22,42 @@
* Daniel Espinosa <esodan gmail com>
*/
+/**
+ * An {@link GXml.XPathObject} implementation using
+ * libxml2 engine.
+ */
public class GXml.LXPathObject : GLib.Object, GXml.XPathObject {
private GXml.HTMLCollection _collection;
private GXml.XPathObjectType _object_type;
+ private Xml.XPath.Object* _pointer = null;
private bool _boolean_value;
private string _string_value;
private double _number_value;
public LXPathObject (GXml.XDocument document, Xml.XPath.Object* pointer) {
_collection = new GXml.HTMLCollection();
+ _pointer = pointer;
+
+ _object_type = (GXml.XPathObjectType) _pointer->type;
- _object_type = (GXml.XPathObjectType) pointer->type;
-
- if (_object_type == GXml.XPathObjectType.NODESET)
- for (var i = 0; i < pointer->nodesetval->length(); i++)
- _collection.add (new GXml.XElement (document, pointer->nodesetval->item (i)));
- else if (_object_type == GXml.XPathObjectType.BOOLEAN)
- _boolean_value = pointer->boolval == 1;
- else if (_object_type == GXml.XPathObjectType.STRING)
- _string_value = pointer->stringval;
- else if (object_type == GXml.XPathObjectType.NUMBER)
- _number_value = pointer->floatval;
+ if (_object_type == GXml.XPathObjectType.NODESET) {
+ for (var i = 0; i < _pointer->nodesetval->length(); i++) {
+ _collection.add (new GXml.XElement (document, _pointer->nodesetval->item (i)));
+ }
+ } else if (_object_type == GXml.XPathObjectType.BOOLEAN) {
+ _boolean_value = _pointer->boolval == 1;
+ } else if (_object_type == GXml.XPathObjectType.STRING) {
+ _string_value = _pointer->stringval;
+ } else if (object_type == GXml.XPathObjectType.NUMBER) {
+ _number_value = _pointer->floatval;
+ }
+ }
+
+ ~ LXPathObject () {
+ if (_pointer != null) {
+ delete _pointer;
+ _pointer = null;
+ }
}
public GXml.XPathObjectType object_type { get { return _object_type; } }
diff --git a/gxml/XDocument.vala b/gxml/XDocument.vala
index ac7d4ad..fea8ef4 100644
--- a/gxml/XDocument.vala
+++ b/gxml/XDocument.vala
@@ -79,7 +79,14 @@ public class GXml.XDocument : GXml.XNode,
/**
* Gigen {@link Xml.Doc} is owned by this
*/
- public XDocument.from_doc (Xml.Doc doc) { this.doc = doc; }
+ public XDocument.from_doc (Xml.Doc doc) {
+ if (this.doc != null) {
+ delete this.doc;
+ this.doc = null;
+ }
+
+ this.doc = doc;
+ }
public Parser GXml.DomDocument.get_xml_parser () {
if (_parser != null) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]