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

Prevent use-after-free on scope-stored data #2

Open
DasLixou opened this issue Apr 4, 2024 · 2 comments
Open

Prevent use-after-free on scope-stored data #2

DasLixou opened this issue Apr 4, 2024 · 2 comments

Comments

@DasLixou
Copy link
Owner

DasLixou commented Apr 4, 2024

Things like

cx.sub_scope(|cx: &mut Context<'_, '_>| {
    let val = cx.store(42);
    cx.close_scope(cx.scope);
    println!("{val}");
});

shouldn't be possible.
This should be a compile time error via lifetimes somehow.
Also this could be a problem:

cx.sub_scope(|cx: &mut Context<'_, '_>| {
    let val = cx.store(42);
    let kill_switch = EventStation::new();
    let s = cx.scope;
    station.listen(
        s,
        move |_event: &KillSignal, cx: &mut Context<'_, '_>| {
            cx.close_scope(s);
        },
    );
    // this will be a problem:
    kill_switch.fire();
    println!("{val}");
    // while this would be fine:
    let button = /* .. */;
    button.on_press.listen(s, |_, _| { kill_switch.fire(); });
});
@DasLixou
Copy link
Owner Author

DasLixou commented Apr 5, 2024

One idea that is not directly related to that but could help: Storing all stores in one big store and then having it indexed by a storekey with lifetime maybe?

@DasLixou
Copy link
Owner Author

DasLixou commented Apr 5, 2024

Ideally we don't even return to the building function or store the close_scopes up till all building is done? (but that may be a little bit of waiting when theres lots to build)

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

No branches or pull requests

1 participant