[librsvg/rustification] gradient.rs: Destroy the gradient that we created with the C helper function



commit 5e362661b769fb5d5d639d4937f4b25e8801003c
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Nov 30 21:26:03 2016 -0600

    gradient.rs: Destroy the gradient that we created with the C helper function
    
    ... even though the helper called back into Rust to create the gradient!

 rust/src/gradient.rs |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)
---
diff --git a/rust/src/gradient.rs b/rust/src/gradient.rs
index 2aea433..aa27c9b 100644
--- a/rust/src/gradient.rs
+++ b/rust/src/gradient.rs
@@ -318,6 +318,10 @@ impl Drop for NodeFallbackSource {
     }
 }
 
+extern "C" {
+    fn rsvg_gradient_node_to_rust_gradient (node: *const RsvgNode) -> *mut Gradient;
+}
+
 impl FallbackSource for NodeFallbackSource {
     fn get_fallback (&mut self, name: &str) -> Option<Gradient> {
         let fallback_node = drawing_ctx::acquire_node (self.draw_ctx, name);
@@ -335,8 +339,11 @@ impl FallbackSource for NodeFallbackSource {
         }
 
         let fallback_gradient: &mut Gradient = unsafe { &mut (*raw_fallback_gradient) };
+        let cloned = fallback_gradient.clone ();
+
+        unsafe { gradient_destroy (raw_fallback_gradient); }
 
-        return Some (fallback_gradient.clone ());
+        return Some (cloned);
     }
 }
 
@@ -585,10 +592,6 @@ pub extern fn gradient_add_color_stop (raw_gradient: *mut Gradient,
     gradient.add_color_stop (offset, rgba);
 }
 
-extern "C" {
-    fn rsvg_gradient_node_to_rust_gradient (node: *const RsvgNode) -> *mut Gradient;
-}
-
 #[no_mangle]
 pub extern fn gradient_resolve_fallbacks_and_set_pattern (raw_gradient: *mut Gradient,
                                                           draw_ctx:     *mut RsvgDrawingCtx,


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