Skip to content

GlobalLock without corresponding GlobalUnlock #549

Open

Description

@meithecatte

In the Windows implementation of get_raw_clipboard, GlobalLock is called without a corresponding GlobalUnlock:

let data_ptr = GlobalLock(clipboard_data) as *const u16;
if data_ptr.is_null() {
return None;
}
let data_size = GlobalSize(clipboard_data) as usize;
let slice = std::slice::from_raw_parts(data_ptr, data_size);
let len = slice.iter().position(|b| *b == 0).unwrap_or(data_size);
// search for the first null byte to see where the string ends.
let mut res = vec![0; len];
ptr::copy_nonoverlapping(data_ptr, res.as_mut_ptr(), len);
Some(res)
}

According to the WinAPI docs, this is wrong:

Each successful call that a process makes to GlobalLock for an object must be matched by a corresponding call to GlobalUnlock.
– https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globallock

The application must not free the handle nor leave it locked.
– https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getclipboarddata

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions