Fix ASAN error when Wayland fell back to X11

An alternative fix to [0] which caused an error with ASAN
(freeing an GHOST_ISystem instead of a GHOST_System).
Reported by @Baardaap in chat, I'm unable to reproduce the issue.

Instead of calling the destructor directly, add a private method that
deletes data before raising an exception.

[0]: fd36221930
This commit is contained in:
Campbell Barton 2023-01-16 15:15:47 +11:00
parent a294c35370
commit 5cbc8ce3b1
2 changed files with 16 additions and 5 deletions

View File

@ -5328,7 +5328,7 @@ GHOST_SystemWayland::GHOST_SystemWayland(bool background)
/* Connect to the Wayland server. */
display_->wl_display = wl_display_connect(nullptr);
if (!display_->wl_display) {
this->~GHOST_SystemWayland();
display_destroy_and_free_all();
throw std::runtime_error("Wayland: unable to connect to display!");
}
@ -5372,7 +5372,7 @@ GHOST_SystemWayland::GHOST_SystemWayland(bool background)
"WAYLAND found but libdecor was not, install libdecor for Wayland support, "
"falling back to X11\n");
# endif
this->~GHOST_SystemWayland();
display_destroy_and_free_all();
throw std::runtime_error("Wayland: unable to find libdecor!");
use_libdecor = true;
@ -5389,7 +5389,7 @@ GHOST_SystemWayland::GHOST_SystemWayland(bool background)
GWL_LibDecor_System &decor = *display_->libdecor;
decor.context = libdecor_new(display_->wl_display, &libdecor_interface);
if (!decor.context) {
this->~GHOST_SystemWayland();
display_destroy_and_free_all();
throw std::runtime_error("Wayland: unable to create window decorations!");
}
}
@ -5400,7 +5400,7 @@ GHOST_SystemWayland::GHOST_SystemWayland(bool background)
{
GWL_XDG_Decor_System &decor = *display_->xdg_decor;
if (!decor.shell) {
this->~GHOST_SystemWayland();
display_destroy_and_free_all();
throw std::runtime_error("Wayland: unable to access xdg_shell!");
}
}
@ -5410,7 +5410,7 @@ GHOST_SystemWayland::GHOST_SystemWayland(bool background)
#endif
}
GHOST_SystemWayland::~GHOST_SystemWayland()
void GHOST_SystemWayland::display_destroy_and_free_all()
{
gwl_display_destroy(display_);
@ -5420,6 +5420,11 @@ GHOST_SystemWayland::~GHOST_SystemWayland()
#endif
}
GHOST_SystemWayland::~GHOST_SystemWayland()
{
display_destroy_and_free_all();
}
GHOST_TSuccess GHOST_SystemWayland::init()
{
GHOST_TSuccess success = GHOST_System::init();

View File

@ -242,5 +242,11 @@ class GHOST_SystemWayland : public GHOST_System {
#endif
private:
/**
* Support freeing the internal data separately from the destructor
* so it can be called when WAYLAND isn't running (immediately before raising an exception).
*/
void display_destroy_and_free_all();
struct GWL_Display *display_;
};