From 1c73beaf9bf98ba76f89fbfc137b51a0c92063a3 Mon Sep 17 00:00:00 2001 From: Tom Englund Date: Fri, 3 May 2024 19:10:41 +0200 Subject: [PATCH] inputmgr: dont double free on hotplug (#5855) * inputmgr: dont double free on hotplug since we are also unrefing the state on hotplugging the keyboard set the state to nullptr so the destructor if case actually catches its been already freed. * keybindgmgr: dont double free on layout switching d5bf153 added keymap unref at the end of updateXKBTranslationState to not leak it when exiting, only it causes updateXKBTranslationState to double free when changing layouts. since its already freed. remove the unneeded extra xkb_keymap_unref. --- src/managers/KeybindManager.cpp | 1 - src/managers/input/InputManager.cpp | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index cfad932a..4e98a301 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -181,7 +181,6 @@ uint32_t CKeybindManager::keycodeToModifier(xkb_keycode_t keycode) { void CKeybindManager::updateXKBTranslationState() { if (m_pXKBTranslationState) { - xkb_keymap_unref(xkb_state_get_keymap(m_pXKBTranslationState)); xkb_state_unref(m_pXKBTranslationState); m_pXKBTranslationState = nullptr; diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 58b5caa3..fb9d2b8a 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -1195,6 +1195,7 @@ void CInputManager::destroyKeyboard(SKeyboard* pKeyboard) { pKeyboard->hyprListener_keyboardKey.removeCallback(); xkb_state_unref(pKeyboard->xkbTranslationState); + pKeyboard->xkbTranslationState = nullptr; m_lKeyboards.remove(*pKeyboard);