From 520a30f3c7c22412cd2ea1c0e892aab7e36b95e1 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 15 Jul 2022 15:12:54 +0900 Subject: [PATCH] internal/gamepad: bug fix: memory leak on Xbox Updates #2084 --- internal/gamepad/api_xbox_windows.go | 4 ++++ internal/gamepad/gamepad_xbox_windows.go | 1 + 2 files changed, 5 insertions(+) diff --git a/internal/gamepad/api_xbox_windows.go b/internal/gamepad/api_xbox_windows.go index e33f6925e..581b33826 100644 --- a/internal/gamepad/api_xbox_windows.go +++ b/internal/gamepad/api_xbox_windows.go @@ -246,3 +246,7 @@ func (i *_IGameInputReading) GetGamepadState() (_GameInputGamepadState, bool) { r, _, _ := syscall.Syscall(i.vtbl.GetGamepadState, 2, uintptr(unsafe.Pointer(i)), uintptr(unsafe.Pointer(&state)), 0) return state, int32(r) != 0 } + +func (i *_IGameInputReading) Release() { + syscall.Syscall(i.vtbl.Release, 1, uintptr(unsafe.Pointer(i)), 0, 0) +} diff --git a/internal/gamepad/gamepad_xbox_windows.go b/internal/gamepad/gamepad_xbox_windows.go index 10ef6ccaa..2aa04ccdd 100644 --- a/internal/gamepad/gamepad_xbox_windows.go +++ b/internal/gamepad/gamepad_xbox_windows.go @@ -131,6 +131,7 @@ func (n *nativeGamepadXbox) update(gamepads *gamepads) error { if err != nil { return err } + defer r.Release() state, ok := r.GetGamepadState() if !ok {