[Bf-blender-cvs] [5cbc8ce3b14] master: Fix ASAN error when Wayland fell back to X11

Campbell Barton noreply at git.blender.org
Mon Jan 16 05:31:18 CET 2023


Commit: 5cbc8ce3b14558cf208f30cc01aea55e00816003
Author: Campbell Barton
Date:   Mon Jan 16 15:15:47 2023 +1100
Branches: master
https://developer.blender.org/rB5cbc8ce3b14558cf208f30cc01aea55e00816003

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]: fd36221930e35efd2c09af8fb91234a510e3b9dc

===================================================================

M	intern/ghost/intern/GHOST_SystemWayland.cpp
M	intern/ghost/intern/GHOST_SystemWayland.h

===================================================================

diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp
index fbe5159ea78..6a163d8661e 100644
--- a/intern/ghost/intern/GHOST_SystemWayland.cpp
+++ b/intern/ghost/intern/GHOST_SystemWayland.cpp
@@ -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();
diff --git a/intern/ghost/intern/GHOST_SystemWayland.h b/intern/ghost/intern/GHOST_SystemWayland.h
index c745d3b1d36..44026d5efad 100644
--- a/intern/ghost/intern/GHOST_SystemWayland.h
+++ b/intern/ghost/intern/GHOST_SystemWayland.h
@@ -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_;
 };



More information about the Bf-blender-cvs mailing list