internal: fix a few asan reported leaks on exit of hyprland (#5852)

* 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.

* 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.

* 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.

* 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.

* skeyboard: add destructor and free state

free the state on destruction of keyboard, reported as leak by asan
This commit is contained in:
Tom Englund 2024-05-03 15:42:08 +02:00 committed by GitHub
parent 387127b12a
commit d5bf15387a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 41 additions and 1 deletions

View File

@ -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;
}

View File

@ -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<SNotification>()).get();

View File

@ -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);

View File

@ -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 {

View File

@ -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; });
}

View File

@ -13,6 +13,7 @@ struct wlr_xwayland;
class CCursorManager {
public:
CCursorManager();
~CCursorManager();
wlr_buffer* getCursorBuffer();

View File

@ -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() {

View File

@ -58,6 +58,7 @@ struct SParsedKey {
class CKeybindManager {
public:
CKeybindManager();
~CKeybindManager();
bool onKeyEvent(wlr_keyboard_key_event*, SKeyboard*);
bool onAxisEvent(wlr_pointer_axis_event*);