[librsvg] Defs: free the extern RsvgHandles on Drop



commit 0b082e0358ca7d213d3db68e6d77aae2445d46ba
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Jan 9 15:47:30 2019 -0600

    Defs: free the extern RsvgHandles on Drop

 rsvg_internals/src/defs.rs   | 12 +++++++++++-
 rsvg_internals/src/handle.rs |  2 +-
 2 files changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/rsvg_internals/src/defs.rs b/rsvg_internals/src/defs.rs
index 5e3e4bec..5c0374a4 100644
--- a/rsvg_internals/src/defs.rs
+++ b/rsvg_internals/src/defs.rs
@@ -3,6 +3,8 @@ use std::collections::HashMap;
 use std::fmt;
 use std::rc::Rc;
 
+use gobject_sys;
+
 use allowed_url::AllowedUrl;
 use error::ValueErrorKind;
 use handle::{self, LoadOptions, RsvgHandle};
@@ -10,7 +12,7 @@ use node::Node;
 use parsers::ParseError;
 
 pub struct Defs {
-    externs: HashMap<AllowedUrl, *const RsvgHandle>,
+    externs: HashMap<AllowedUrl, *mut RsvgHandle>,
 }
 
 impl Defs {
@@ -51,6 +53,14 @@ impl Defs {
     }
 }
 
+impl Drop for Defs {
+    fn drop(&mut self) {
+        for (_, handle) in self.externs.iter() {
+            unsafe { gobject_sys::g_object_unref(*handle as *mut _); }
+        }
+    }
+}
+
 /// Parsed result of an href from an SVG or CSS file
 ///
 /// Sometimes in SVG element references (e.g. the `href` in the `<feImage>` element) we
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index 42ff9d97..900645f7 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -622,7 +622,7 @@ pub fn lookup_fragment_id(handle: *const RsvgHandle, id: &str) -> Option<Rc<Node
     svg.lookup_node_by_id(id)
 }
 
-pub fn load_extern(load_options: &LoadOptions, aurl: &AllowedUrl) -> Result<*const RsvgHandle, ()> {
+pub fn load_extern(load_options: &LoadOptions, aurl: &AllowedUrl) -> Result<*mut RsvgHandle, ()> {
     unsafe {
         let file = gio::File::new_for_uri(aurl.url().as_str());
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]