diff options
| author | Tom Englund <tomenglund26@gmail.com> | 2024-07-29 19:19:47 +0200 |
|---|---|---|
| committer | Vaxry <vaxry@vaxry.net> | 2024-07-29 19:29:08 +0200 |
| commit | 9c38b0fdbe32dc2cb81d53c9be90113d114f1cd2 (patch) | |
| tree | 1e7b6c42be23f8164e5dd0742d3b131b2850cd01 /src/protocols/GlobalShortcuts.cpp | |
| parent | 60b663e2765c4cdb7e14fff75c4f88bf7ae312e2 (diff) | |
core: add a destructor to CHyprOpenglImpl and avoid wl_container_of undefined behaviour (#7101)
* protocols: avoid undefined behaviour in C macro
to safely use wl_container_of with a class the class has to be no
virtual functions, no inheritance, and uniform access control (e.g all
public)
work around this by putting this into a destroywrapper struct.
* opengl: clean memory on destruction
add a destructor and free the allocated memory and close the fd
Diffstat (limited to 'src/protocols/GlobalShortcuts.cpp')
| -rw-r--r-- | src/protocols/GlobalShortcuts.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/protocols/GlobalShortcuts.cpp b/src/protocols/GlobalShortcuts.cpp index 898f0e07..7eb84be6 100644 --- a/src/protocols/GlobalShortcuts.cpp +++ b/src/protocols/GlobalShortcuts.cpp @@ -8,13 +8,14 @@ static void bindManagerInt(wl_client* client, void* data, uint32_t version, uint } static void handleDisplayDestroy(struct wl_listener* listener, void* data) { - CGlobalShortcutsProtocolManager* proto = wl_container_of(listener, proto, m_liDisplayDestroy); + CGlobalShortcutsProtocolManagerDestroyWrapper* wrap = wl_container_of(listener, wrap, listener); + CGlobalShortcutsProtocolManager* proto = wrap->parent; proto->displayDestroy(); } void CGlobalShortcutsProtocolManager::displayDestroy() { - wl_list_remove(&m_liDisplayDestroy.link); - wl_list_init(&m_liDisplayDestroy.link); + wl_list_remove(&m_liDisplayDestroy.listener.link); + wl_list_init(&m_liDisplayDestroy.listener.link); wl_global_destroy(m_pGlobal); } @@ -30,8 +31,10 @@ CGlobalShortcutsProtocolManager::CGlobalShortcutsProtocolManager() { return; } - m_liDisplayDestroy.notify = handleDisplayDestroy; - wl_display_add_destroy_listener(g_pCompositor->m_sWLDisplay, &m_liDisplayDestroy); + wl_list_init(&m_liDisplayDestroy.listener.link); + m_liDisplayDestroy.listener.notify = handleDisplayDestroy; + m_liDisplayDestroy.parent = this; + wl_display_add_destroy_listener(g_pCompositor->m_sWLDisplay, &m_liDisplayDestroy.listener); Debug::log(LOG, "GlobalShortcutsManager started successfully!"); } |
