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.
This commit is contained in:
Tom Englund 2024-05-25 20:05:37 +02:00 committed by GitHub
parent 972c1c27e6
commit 58c93d8de8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 18 additions and 0 deletions

View file

@ -142,6 +142,7 @@ void CSessionLockSurface::render() {
} }
void CSessionLockSurface::onCallback() { void CSessionLockSurface::onCallback() {
wl_callback_destroy(frameCallback);
frameCallback = nullptr; frameCallback = nullptr;
if (needsFrame && !g_pHyprlock->m_bTerminate && g_pEGL) if (needsFrame && !g_pHyprlock->m_bTerminate && g_pEGL)

View file

@ -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 // wl_seat
static void handleCapabilities(void* data, wl_seat* wl_seat, uint32_t capabilities); 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); 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) { static void dmabufFeedbackFormatTable(void* data, zwp_linux_dmabuf_feedback_v1* feedback, int fd, uint32_t size) {

View file

@ -29,6 +29,7 @@ struct SDMABUFModifier {
class CHyprlock { class CHyprlock {
public: public:
CHyprlock(const std::string& wlDisplay, const bool immediate); CHyprlock(const std::string& wlDisplay, const bool immediate);
~CHyprlock();
void run(); void run();

View file

@ -326,6 +326,9 @@ void CAsyncResourceGatherer::renderText(const SPreloadRequest& rq) {
if (!attrList) if (!attrList)
attrList = pango_attr_list_new(); attrList = pango_attr_list_new();
if (buf)
free(buf);
pango_attr_list_insert(attrList, pango_attr_scale_new(1)); pango_attr_list_insert(attrList, pango_attr_scale_new(1));
pango_layout_set_attributes(layout, attrList); pango_layout_set_attributes(layout, attrList);
pango_attr_list_unref(attrList); pango_attr_list_unref(attrList);

View file

@ -8,6 +8,7 @@ class IWidget {
struct SRenderData { struct SRenderData {
float opacity = 1; float opacity = 1;
}; };
virtual ~IWidget() = default;
virtual bool draw(const SRenderData& data) = 0; virtual bool draw(const SRenderData& data) = 0;