Skip to content

vsgWin32::Win32_Window continues using HWND after it's been destroyed #1254

@AnyOldName3

Description

@AnyOldName3

vsgWin32::Win32_Window attempts to destroy its window handle, _window, in its destructor by calling DestroyWindow(_window). However, because vsgWin32::Win32WindowProc (the window message handling CALLBACK) calls DefWindowProc (the default window message handler), when a WM_CLOSE message is received, the window's closed and destroyed before the destructor runs.

This is especially bad because HWNDs are reused for new windows, so the destructor could potentially destroy another process' unrelated window. Thankfully, it's unlikely as Windows actively defends against this kind of bug, using some of a HWND's bits for the window table index and some for a generation number so the same index won't turn into the same HWND when it's reused until those bits have been exhausted.

I used this patch to identify the unwanted window murderer, based on this OldNewThing post: https://devblogs.microsoft.com/oldnewthing/20111026-00/?p=9263
who-killed-my-window.patch

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