gpu_display: fix a potential memory leak in thread_message_util.

If PeekMessageW() does retrieve a message, we are responsibe for
dropping it.

Bug: 244489783
Test: Ran GPG
Change-Id: I69250387cc93698513a47d38de52d161a0026692
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4719207
Reviewed-by: Pujun Lun <lunpujun@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Kaiyi Li <kaiyili@google.com>
This commit is contained in:
lunpujun 2022-11-02 14:24:34 -07:00 committed by crosvm LUCI
parent baf1937010
commit ca35151bc1

View file

@ -20,16 +20,22 @@ use winapi::um::winuser::*;
/// It does no harm calling this function multiple times, since it won't remove any message from the
/// queue.
pub(crate) fn force_create_message_queue() {
// Safe because if `message` is initialized, we will extract and drop the value.
let mut message = mem::MaybeUninit::uninit();
// Safe because we know the lifetime of `message`, and `PeekMessageW()` has no failure mode.
unsafe {
if unsafe {
PeekMessageW(
message.as_mut_ptr(),
null_mut(),
WM_USER,
WM_USER,
PM_NOREMOVE,
);
) != 0
} {
// Safe because `PeekMessageW()` has populated `message`.
unsafe {
message.assume_init_drop();
}
}
}