Skip to content

Memory usage after free #2

@Mart-Bogdan

Description

@Mart-Bogdan

Hello, I took a look at your sample app, and it has memory safety issue at https://github.com/S2dentik/Rust-Win32-SampleApp/blob/lab1/src/main.rs#L101

fn toWstring(str: &str) -> *const u16 {
    unsafe {
        let v: Vec<u16> = OsStr::new(str).encode_wide().chain(Some(0).into_iter()).collect();
        return v.as_ptr();
    }
}

It allocates Vec, which uses Heap buffer, and then returns pointer to a buffer, but pointer gets used after varable v is our of scope, so is dropped.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions