mirror of
https://github.com/hyprwm/Hyprland.git
synced 2025-08-26 09:23:48 -07:00
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
This commit is contained in:
@@ -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!");
|
||||
}
|
||||
|
Reference in New Issue
Block a user