Commit 2d3ddca1 authored by Federico Mena Quintero's avatar Federico Mena Quintero

gitlab#325 - rsvg_tree_free(): Cast the tree to our real Tree so it will get dropped

We had this:

pub extern "C" fn rsvg_tree_free(tree: *mut RsvgTree) {
    if !tree.is_null() {
        let _ = unsafe { Box::from_raw(tree) };
                         ^ gets a Box<RsvgTree>, which is a box of a zero-sized enum

I.e. it frees zero bytes :)

With need this rebinding:

    let tree = unsafe { &mut *(tree as *mut Tree) };

i.e. cast tree as *mut Tree, so we'll end up with a Box<Tree>
which *can* be dropped as appropriate.

#325
parent afdb457e
......@@ -42,6 +42,7 @@ pub extern "C" fn rsvg_tree_new(root: *const RsvgNode) -> *mut RsvgTree {
#[no_mangle]
pub extern "C" fn rsvg_tree_free(tree: *mut RsvgTree) {
if !tree.is_null() {
let tree = unsafe { &mut *(tree as *mut Tree) };
let _ = unsafe { Box::from_raw(tree) };
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment