Skip to content

Commit

Permalink
core: fix a few small memory leaks on exit (#6470)
Browse files Browse the repository at this point in the history
* renderer: add destructor and destroy event source

add destructor and destroy the event source.
one less leak on exit of compositor reported by asan.

* compositor: cleanup eventloop on exit

destruct hyprctl to release the event sources, and properly cleanup the
event loop on exit of compositor. less leaks on exit reported by asan

* threadmgr: destroy event source on destruction

destroy the event source on destruction.

* eventloopmgr: reset eventloopmgr on exit aswell

reset the eventloopmanager on exit of compositor and free the leaking
last idle frame on monitor destroy.
  • Loading branch information
gulafaran authored Jun 13, 2024
1 parent 9e78104 commit e6d1053
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ void CCompositor::cleanup() {
g_pXWaylandManager.reset();
g_pPointerManager.reset();
g_pSeatManager.reset();
g_pHyprCtl.reset();
g_pEventLoopManager.reset();

if (m_sWLRRenderer)
wlr_renderer_destroy(m_sWLRRenderer);
Expand All @@ -364,6 +366,7 @@ void CCompositor::cleanup() {
if (m_critSigSource)
wl_event_source_remove(m_critSigSource);

wl_event_loop_destroy(m_sWLEventLoop);
wl_display_terminate(m_sWLDisplay);
m_sWLDisplay = nullptr;

Expand Down
3 changes: 3 additions & 0 deletions src/events/Monitors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ void Events::listener_monitorDestroy(void* owner, void* data) {

Debug::log(LOG, "Destroy called for monitor {}", pMonitor->output->name);

if (pMonitor->output->idle_frame)
wl_event_source_remove(pMonitor->output->idle_frame);

pMonitor->onDisconnect(true);

pMonitor->output = nullptr;
Expand Down
3 changes: 2 additions & 1 deletion src/managers/ThreadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ CThreadManager::CThreadManager() {
}

CThreadManager::~CThreadManager() {
//
if (m_esConfigTimer)
wl_event_source_remove(m_esConfigTimer);
}
5 changes: 5 additions & 0 deletions src/render/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ CHyprRenderer::CHyprRenderer() {
wl_event_source_timer_update(m_pCursorTicker, 500);
}

CHyprRenderer::~CHyprRenderer() {
if (m_pCursorTicker)
wl_event_source_remove(m_pCursorTicker);
}

static void renderSurface(SP<CWLSurfaceResource> surface, int x, int y, void* data) {
if (!surface->current.buffer || !surface->current.buffer->texture)
return;
Expand Down
1 change: 1 addition & 0 deletions src/render/Renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct SSessionLockSurface;
class CHyprRenderer {
public:
CHyprRenderer();
~CHyprRenderer();

void renderMonitor(CMonitor* pMonitor);
void arrangeLayersForMonitor(const int&);
Expand Down

0 comments on commit e6d1053

Please sign in to comment.