From b4b73ba0a4e3ebd735b94cd8d601cdc013004223 Mon Sep 17 00:00:00 2001 From: Tom Englund Date: Fri, 3 May 2024 13:13:08 +0200 Subject: [PATCH 1/5] notifications: free cairo images on destruction asan reports a leak on exit if we dont free the image we created in the draw function. add a destructor and free images on exit. --- src/debug/HyprNotificationOverlay.cpp | 7 +++++++ src/debug/HyprNotificationOverlay.hpp | 1 + 2 files changed, 8 insertions(+) diff --git a/src/debug/HyprNotificationOverlay.cpp b/src/debug/HyprNotificationOverlay.cpp index 2f00d9789a8..80c80601709 100644 --- a/src/debug/HyprNotificationOverlay.cpp +++ b/src/debug/HyprNotificationOverlay.cpp @@ -36,6 +36,13 @@ CHyprNotificationOverlay::CHyprNotificationOverlay() { m_szIconFontName = fonts.substr(COLON + 2, LASTCHAR - (COLON + 2)); } +CHyprNotificationOverlay::~CHyprNotificationOverlay() { + if (m_pCairo) + cairo_destroy(m_pCairo); + if (m_pCairoSurface) + cairo_surface_destroy(m_pCairoSurface); +} + void CHyprNotificationOverlay::addNotification(const std::string& text, const CColor& color, const float timeMs, const eIcons icon, const float fontSize) { const auto PNOTIF = m_dNotifications.emplace_back(std::make_unique()).get(); diff --git a/src/debug/HyprNotificationOverlay.hpp b/src/debug/HyprNotificationOverlay.hpp index 25934734837..d086ada901f 100644 --- a/src/debug/HyprNotificationOverlay.hpp +++ b/src/debug/HyprNotificationOverlay.hpp @@ -39,6 +39,7 @@ struct SNotification { class CHyprNotificationOverlay { public: CHyprNotificationOverlay(); + ~CHyprNotificationOverlay(); void draw(CMonitor* pMonitor); void addNotification(const std::string& text, const CColor& color, const float timeMs, const eIcons icon = ICON_NONE, const float fontSize = 13.f); From fe7cdb39690bff4b0fb0cfa6e268e3ca4040f9b8 Mon Sep 17 00:00:00 2001 From: Tom Englund Date: Fri, 3 May 2024 14:19:31 +0200 Subject: [PATCH 2/5] compositor: destroy wlroots types on exit there are a few types not being destroyed on exit and causing a leak on exit in wlroots reported by asan, add those. --- src/Compositor.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 3f53f6c3bae..ea88bec1e7a 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -421,8 +421,22 @@ void CCompositor::cleanup() { g_pWatchdog.reset(); g_pXWaylandManager.reset(); - wl_display_terminate(m_sWLDisplay); + if (m_sWLRCursor) + wlr_cursor_destroy(m_sWLRCursor); + + if (m_sSeat.seat) + wlr_seat_destroy(m_sSeat.seat); + + if (m_sWLRRenderer) + wlr_renderer_destroy(m_sWLRRenderer); + + if (m_sWLRAllocator) + wlr_allocator_destroy(m_sWLRAllocator); + if (m_sWLRBackend) + wlr_backend_destroy(m_sWLRBackend); + + wl_display_terminate(m_sWLDisplay); m_sWLDisplay = nullptr; } From 144af93b317de9d66bcbe3331e99f4975aae7c57 Mon Sep 17 00:00:00 2001 From: Tom Englund Date: Fri, 3 May 2024 14:35:33 +0200 Subject: [PATCH 3/5] cursormgr: ensure we destroy cursor mgr on exit add a destructor and call wlr_xcursor_manager_destroy on the manager on destruction, leak reported by asan. --- src/managers/CursorManager.cpp | 5 +++++ src/managers/CursorManager.hpp | 1 + 2 files changed, 6 insertions(+) diff --git a/src/managers/CursorManager.cpp b/src/managers/CursorManager.cpp index fa5ee8cdd34..3fcecfe4335 100644 --- a/src/managers/CursorManager.cpp +++ b/src/managers/CursorManager.cpp @@ -53,6 +53,11 @@ CCursorManager::CCursorManager() { static auto P = g_pHookSystem->hookDynamic("monitorLayoutChanged", [this](void* self, SCallbackInfo& info, std::any param) { this->updateTheme(); }); } +CCursorManager::~CCursorManager() { + if (m_pWLRXCursorMgr) + wlr_xcursor_manager_destroy(m_pWLRXCursorMgr); +} + void CCursorManager::dropBufferRef(CCursorManager::CCursorBuffer* ref) { std::erase_if(m_vCursorBuffers, [ref](const auto& buf) { return buf.get() == ref; }); } diff --git a/src/managers/CursorManager.hpp b/src/managers/CursorManager.hpp index ff633592de6..629f29e1110 100644 --- a/src/managers/CursorManager.hpp +++ b/src/managers/CursorManager.hpp @@ -13,6 +13,7 @@ struct wlr_xwayland; class CCursorManager { public: CCursorManager(); + ~CCursorManager(); wlr_buffer* getCursorBuffer(); From 8576f90eeeda799fa26e5fe15252c2a9a7be286f Mon Sep 17 00:00:00 2001 From: Tom Englund Date: Fri, 3 May 2024 15:18:50 +0200 Subject: [PATCH 4/5] keybindmgr: free state and keymap add missing keymap_unref on creation, and add a destructor and free the state on exit. leak reported by asan. --- src/managers/KeybindManager.cpp | 6 ++++++ src/managers/KeybindManager.hpp | 1 + 2 files changed, 7 insertions(+) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 1150ac2ef67..cfad932af64 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -116,6 +116,11 @@ CKeybindManager::CKeybindManager() { }); } +CKeybindManager::~CKeybindManager() { + if (m_pXKBTranslationState) + xkb_state_unref(m_pXKBTranslationState); +} + void CKeybindManager::addKeybind(SKeybind kb) { m_lKeybinds.push_back(kb); @@ -219,6 +224,7 @@ void CKeybindManager::updateXKBTranslationState() { xkb_context_unref(PCONTEXT); m_pXKBTranslationState = xkb_state_new(PKEYMAP); + xkb_keymap_unref(PKEYMAP); } bool CKeybindManager::ensureMouseBindState() { diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index deb25ae99d4..24e71c6a055 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -58,6 +58,7 @@ struct SParsedKey { class CKeybindManager { public: CKeybindManager(); + ~CKeybindManager(); bool onKeyEvent(wlr_keyboard_key_event*, SKeyboard*); bool onAxisEvent(wlr_pointer_axis_event*); From 1f899b5479914f0698b68569bd215c46264ebea3 Mon Sep 17 00:00:00 2001 From: Tom Englund Date: Fri, 3 May 2024 15:24:04 +0200 Subject: [PATCH 5/5] skeyboard: add destructor and free state free the state on destruction of keyboard, reported as leak by asan --- src/helpers/WLClasses.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index 7eaebead04e..c625aae0f77 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -102,6 +102,11 @@ struct SKeyboard { bool operator==(const SKeyboard& rhs) const { return keyboard == rhs.keyboard; } + + ~SKeyboard() { + if (xkbTranslationState) + xkb_state_unref(xkbTranslationState); + } }; struct SMouse {