From 58c93d8de886e06f57875fc651d60e2dcfc32989 Mon Sep 17 00:00:00 2001 From: Tom Englund Date: Sat, 25 May 2024 20:05:37 +0200 Subject: [PATCH] core: fix a few reported leaks by asan (#349) * widgets: add missing virtual destructor destructor is missing and as a consequence all sub classes gets wrongly destructed reported as "new-delete-type-mismatch" by asan. * gatherer: free memory allocated by pango with pango_parse_markup its up to the caller of the function to free the pointer to the text returned stored in this buf. * core: add destructor and free devices add a destructor and free both drmDevice and gbmDevice, leaks reported by asan. * core: free xkb allocated state and keymap free xkb state and keymap on destruction to prevent leak on exit and less asan spam. * locksurface: destroy the surface frame on done the callback was never being destroyed and is leaking on each frameCallback creation, call wl_callback_destroy in onCallback() and free the memory. reported with asan. --- src/core/LockSurface.cpp | 1 + src/core/hyprlock.cpp | 12 ++++++++++++ src/core/hyprlock.hpp | 1 + src/renderer/AsyncResourceGatherer.cpp | 3 +++ src/renderer/widgets/IWidget.hpp | 1 + 5 files changed, 18 insertions(+) diff --git a/src/core/LockSurface.cpp b/src/core/LockSurface.cpp index 755269e..3ffe2a4 100644 --- a/src/core/LockSurface.cpp +++ b/src/core/LockSurface.cpp @@ -142,6 +142,7 @@ void CSessionLockSurface::render() { } void CSessionLockSurface::onCallback() { + wl_callback_destroy(frameCallback); frameCallback = nullptr; if (needsFrame && !g_pHyprlock->m_bTerminate && g_pEGL) diff --git a/src/core/hyprlock.cpp b/src/core/hyprlock.cpp index 2325666..d4c11d3 100644 --- a/src/core/hyprlock.cpp +++ b/src/core/hyprlock.cpp @@ -39,6 +39,17 @@ CHyprlock::CHyprlock(const std::string& wlDisplay, const bool immediate) { } } +CHyprlock::~CHyprlock() { + if (g_pHyprlock->dma.gbmDevice) + gbm_device_destroy(g_pHyprlock->dma.gbmDevice); + + if (g_pHyprlock->m_pXKBState) + xkb_state_unref(g_pHyprlock->m_pXKBState); + + if (g_pHyprlock->m_pXKBKeymap) + xkb_keymap_unref(g_pHyprlock->m_pXKBKeymap); +} + // wl_seat static void handleCapabilities(void* data, wl_seat* wl_seat, uint32_t capabilities); @@ -82,6 +93,7 @@ static void dmabufFeedbackMainDevice(void* data, zwp_linux_dmabuf_feedback_v1* f } g_pHyprlock->dma.gbmDevice = g_pHyprlock->createGBMDevice(drmDev); + drmFreeDevice(&drmDev); } static void dmabufFeedbackFormatTable(void* data, zwp_linux_dmabuf_feedback_v1* feedback, int fd, uint32_t size) { diff --git a/src/core/hyprlock.hpp b/src/core/hyprlock.hpp index 192c286..52344b9 100644 --- a/src/core/hyprlock.hpp +++ b/src/core/hyprlock.hpp @@ -29,6 +29,7 @@ struct SDMABUFModifier { class CHyprlock { public: CHyprlock(const std::string& wlDisplay, const bool immediate); + ~CHyprlock(); void run(); diff --git a/src/renderer/AsyncResourceGatherer.cpp b/src/renderer/AsyncResourceGatherer.cpp index 70f9ec8..f7f46ee 100644 --- a/src/renderer/AsyncResourceGatherer.cpp +++ b/src/renderer/AsyncResourceGatherer.cpp @@ -326,6 +326,9 @@ void CAsyncResourceGatherer::renderText(const SPreloadRequest& rq) { if (!attrList) attrList = pango_attr_list_new(); + if (buf) + free(buf); + pango_attr_list_insert(attrList, pango_attr_scale_new(1)); pango_layout_set_attributes(layout, attrList); pango_attr_list_unref(attrList); diff --git a/src/renderer/widgets/IWidget.hpp b/src/renderer/widgets/IWidget.hpp index ca1a519..8f65b79 100644 --- a/src/renderer/widgets/IWidget.hpp +++ b/src/renderer/widgets/IWidget.hpp @@ -8,6 +8,7 @@ class IWidget { struct SRenderData { float opacity = 1; }; + virtual ~IWidget() = default; virtual bool draw(const SRenderData& data) = 0;