Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Appending elements across documents allows for memory unsafety in safe client code #33

Open
shepmaster opened this issue Jan 15, 2016 · 0 comments

Comments

@shepmaster
Copy link
Owner

extern crate sxd_document;

use sxd_document::Package;

fn main() {
    let p1 = Package::new();

    {
        let p2 = Package::new();

        {
            let d1 = p1.as_document();
            let d2 = p2.as_document();

            let e1 = d1.create_element("hi");
            d2.root().append_child(e1);

            let e2 = d2.create_element("bye");
            d1.root().append_child(e2);
        }
    }

    {
        let d1 = p1.as_document();
        for c in d1.root().children() {
            println!("{:?}", c);
        }
    }
}

When p2 goes out of scope, it takes its children with it, even though p1 retains a reference. Related to #8, but a critical safety issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant