[rygel] mediathek: Plug libXml memory leaks
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] mediathek: Plug libXml memory leaks
- Date: Fri, 28 Jan 2011 12:55:55 +0000 (UTC)
commit 0c8a3a44218bf5a523599ed967a9903ad6f9bf2a
Author: Jens Georg <mail jensge org>
Date: Sun Jan 16 15:01:08 2011 +0100
mediathek: Plug libXml memory leaks
See bgo#639700.
.../rygel-mediathek-asx-playlist-parser.vala | 30 ++++++++++++--------
src/plugins/mediathek/rygel-mediathek-plugin.vala | 5 +++
.../mediathek/rygel-mediathek-rss-container.vala | 23 ++++++++------
3 files changed, 36 insertions(+), 22 deletions(-)
---
diff --git a/src/plugins/mediathek/rygel-mediathek-asx-playlist-parser.vala b/src/plugins/mediathek/rygel-mediathek-asx-playlist-parser.vala
index 14f5fbd..fe40fd3 100644
--- a/src/plugins/mediathek/rygel-mediathek-asx-playlist-parser.vala
+++ b/src/plugins/mediathek/rygel-mediathek-asx-playlist-parser.vala
@@ -57,6 +57,7 @@ internal class Rygel.Mediathek.AsxPlaylistParser : Object {
*/
public async Gee.List<string>? parse (string uri) throws VideoItemError {
var message = new Soup.Message ("GET", uri);
+ ArrayList<string> uris = null;
yield SoupUtils.queue_message (session, message);
@@ -83,25 +84,30 @@ internal class Rygel.Mediathek.AsxPlaylistParser : Object {
("Could not parse playlist");
}
- var context = new XPath.Context (doc);
+ var doc_guard = new GUPnP.XMLDoc (doc);
+ var context = new XPath.Context (doc_guard.doc);
+
var xpath_object = context.eval ("/asx/entry/ref/@href");
- if (xpath_object->type == XPath.ObjectType.NODESET) {
- var uris = new LinkedList<string> ();
- for (int i = 0;
- i < xpath_object->nodesetval->length ();
- i++) {
- var item = xpath_object->nodesetval->item (i);
- uris.add (item->children->content);
- }
+
+ if (xpath_object->type != XPath.ObjectType.NODESET) {
+ xpath_free_object (xpath_object);
+ throw new VideoItemError.XML_PARSE_ERROR
+ ("No uris found in playlist");
+ }
- return uris;
+ uris = new ArrayList<string> ();
+ for (int i = 0;
+ i < xpath_object->nodesetval->length ();
+ i++) {
+ var item = xpath_object->nodesetval->item (i);
+ uris.add (item->children->content);
}
- delete doc;
+ xpath_free_object (xpath_object);
} catch (RegexError error) {
throw new VideoItemError.XML_PARSE_ERROR ("Failed to normalize");
}
- return null;
+ return uris;
}
}
diff --git a/src/plugins/mediathek/rygel-mediathek-plugin.vala b/src/plugins/mediathek/rygel-mediathek-plugin.vala
index 87a8fa5..a4e61d4 100644
--- a/src/plugins/mediathek/rygel-mediathek-plugin.vala
+++ b/src/plugins/mediathek/rygel-mediathek-plugin.vala
@@ -23,6 +23,11 @@
using Rygel;
using GUPnP;
+// remove when bgo#639700 is fixed and "delete" resolves to the free_func and
+// not to g_free
+[CCode (cname = "xmlXPathFreeObject")]
+internal extern void xpath_free_object (Xml.XPath.Object *object);
+
public void module_init (PluginLoader loader) {
if (loader.plugin_disabled (Mediathek.Plugin.NAME)) {
message ("Plugin '%s' disabled by user, ignoring..",
diff --git a/src/plugins/mediathek/rygel-mediathek-rss-container.vala b/src/plugins/mediathek/rygel-mediathek-rss-container.vala
index 9fb00d7..a77de66 100644
--- a/src/plugins/mediathek/rygel-mediathek-rss-container.vala
+++ b/src/plugins/mediathek/rygel-mediathek-rss-container.vala
@@ -79,18 +79,20 @@ public class Rygel.Mediathek.RssContainer : Rygel.SimpleContainer {
return false;
}
+ var guard = new GUPnP.XMLDoc (doc);
+ var context = new XPath.Context (guard.doc);
-
- var context = new XPath.Context (doc);
- var xpo = context.eval ("/rss/channel/title");
- if (xpo->type == XPath.ObjectType.NODESET &&
- xpo->nodesetval->length () > 0) {
+ var xpath_object = context.eval ("/rss/channel/title");
+ if (xpath_object->type == XPath.ObjectType.NODESET &&
+ xpath_object->nodesetval->length () > 0) {
// just use first title (there should be only one)
- this.title = xpo->nodesetval->item (0)->get_content ();
+ this.title = xpath_object->nodesetval->item (0)->get_content ();
}
+ xpath_free_object (xpath_object);
- xpo = context.eval ("/rss/channel/item");
- if (xpo->type != XPath.ObjectType.NODESET) {
+ xpath_object = context.eval ("/rss/channel/item");
+ if (xpath_object->type != XPath.ObjectType.NODESET) {
+ xpath_free_object (xpath_object);
warning ("RSS feed doesn't have items");
return false;
@@ -98,8 +100,8 @@ public class Rygel.Mediathek.RssContainer : Rygel.SimpleContainer {
this.children.clear ();
this.child_count = 0;
- for (int i = 0; i < xpo->nodesetval->length (); i++) {
- var node = xpo->nodesetval->item (i);
+ for (int i = 0; i < xpath_object->nodesetval->length (); i++) {
+ var node = xpath_object->nodesetval->item (i);
try {
var item = yield factory.create (this, node);
if (item != null) {
@@ -111,6 +113,7 @@ public class Rygel.Mediathek.RssContainer : Rygel.SimpleContainer {
}
}
+ xpath_free_object (xpath_object);
this.updated ();
return this.child_count > 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]