Code Monkey home page Code Monkey logo

Comments (4)

wmedrano avatar wmedrano commented on May 26, 2024

Took a stab at it #26
Why does it need the static?
If my model of lifetimes is correct, then the port's would also need to be static in this case.

from rust-jack.

cramertj avatar cramertj commented on May 26, 2024

It's the whole "mem::forget is stable" thing. If you call mem::forget on a Client, the client's registered callbacks will continue to be triggered for the duration of the process (unless you manually deregister them later on). Therefore, any resources used in the callback must be valid for the 'static lifetime.

from rust-jack.

cramertj avatar cramertj commented on May 26, 2024

To give an example, here's a modified version of the playback_capture example that demonstrates this unsoundness:

 let x = 5;
 let x_ref = &x;
 let process_callback =
         ProcessClosure::new(move |ps: &jack::ProcessScope| -> jack::JackControl {
             // x_ref must still be valid here!
             let closure_x = *x_ref;
             out_a.data(ps).buffer().clone_from_slice(in_a.data(ps).buffer());
             out_b.data(ps).buffer().clone_from_slice(in_b.data(ps).buffer());
             jack::JackControl::Continue
         });
 // Activate the client, which starts the processing
 let active_client = client.activate(process_callback).unwrap();
 mem::forget(active_client);
 // Client is forgotten but not deregistered, stack pops up and x is lost
 // Callback then dereferences x_ref and gains access to stack garbage

from rust-jack.

cramertj avatar cramertj commented on May 26, 2024

Fixed in #26

from rust-jack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.