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

Should BStr have an into_raw, some way to purposefully leak? #26

Open
EndilWayfare opened this issue Jul 27, 2021 · 1 comment
Open

Comments

@EndilWayfare
Copy link

EndilWayfare commented Jul 27, 2021

If you're implementing a function that returns a string to foreign COM callers, you should not deallocate the returned BSTR. Since we can't pass a wio::BStr across the boundary, we'd need some way to extract the pointer and make rust forget about it. I don't see that any existing method would allow that.

c.f. ComPtr

@EndilWayfare EndilWayfare changed the title Should Bstr have an into_raw, some way to purposefully leak? Should BStr have an into_raw, some way to purposefully leak? Jul 27, 2021
@EndilWayfare
Copy link
Author

You can, of course, explicitly spell it out in the meantime

pub fn cause_bstr_to_happen() -> winapi::shared::wtypes::BSTR {
    let bstr: BStr = "Hello World".into();
    let ptr = bstr.as_ptr();
    std::mem::forget(bstr);

    ptr
}

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