Skip to content

Windows: HWnd::create_timer leaks an extra thread timer #362

Closed

Description

@tenshiak

Environment

baseview 0.4.1 on Windows.

Problem

In src/wrappers/win32/window/handle.rs, HWnd::create_timer() calls SetTimer(NULL, 0, ...) to obtain an ID, then reset_timer() calls SetTimer(hwnd, id, ...).

These are two separate timers. kill_timer() calls KillTimer(hwnd, id), which stops only the window-owned timer. The original thread timer remains active, including after the window is destroyed. It also leaks if reset_timer() fails.

The SetTimer documentation states that timer identifiers are specific to the associated window. KillTimer requires the same HWND used for creation, including NULL for thread timers.

Repeated timer creation and cancellation therefore accumulates orphaned thread timers.

Observed impact

With continuous redraws, the UI became progressively choppy and froze after several minutes, including while idle. Closing and reopening the window could leave it black.

Fix applied locally

Removed the initial SetTimer(NULL, 0, ...) call and instead allocated unique, nonzero IDs using an overflow-checked atomic counter. create_timer() then creates only the window-owned timer through the existing reset_timer().

reset_timer() and kill_timer() remain unchanged. Creation, reset, and cancellation now use the same HWND/ID pair, and window destruction cleans up the timer. The counter cannot wrap and reuse live IDs.

With the local fix applied, the Windows UI remained open for approximately 30 minutes without freezing or progressive slowdown and stayed fast and responsive.

Activity

  1. added this to the v0.4.X milestone on Oct 25, 2026
  2. added theissue type on Oct 25, 2026
  3. prokopyl commented on Oct 26, 2026

    @prokopyl
    Member

    #365 fixes the issue on my end, can you check if it also fixes it on your system?

  4. tenshiak commented on Oct 26, 2026

    @tenshiak
    Author

    I tried it. It seems to work just fine!

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

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions