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:
Tom Englund 2024-07-29 19:19:47 +02:00 committed by Vaxry
parent 60b663e276
commit 9c38b0fdbe
6 changed files with 47 additions and 12 deletions

View file

@ -6,13 +6,14 @@ static void bindManagerInternal(wl_client* client, void* data, uint32_t ver, uin
}
static void displayDestroyInternal(struct wl_listener* listener, void* data) {
IWaylandProtocol* proto = wl_container_of(listener, proto, m_liDisplayDestroy);
IWaylandProtocolDestroyWrapper* wrap = wl_container_of(listener, wrap, listener);
IWaylandProtocol* proto = wrap->parent;
proto->onDisplayDestroy();
}
void IWaylandProtocol::onDisplayDestroy() {
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);
}
@ -24,8 +25,10 @@ IWaylandProtocol::IWaylandProtocol(const wl_interface* iface, const int& ver, co
return;
}
m_liDisplayDestroy.notify = displayDestroyInternal;
wl_display_add_destroy_listener(g_pCompositor->m_sWLDisplay, &m_liDisplayDestroy);
wl_list_init(&m_liDisplayDestroy.listener.link);
m_liDisplayDestroy.listener.notify = displayDestroyInternal;
m_liDisplayDestroy.parent = this;
wl_display_add_destroy_listener(g_pCompositor->m_sWLDisplay, &m_liDisplayDestroy.listener);
protoLog(LOG, "Registered global");
}