From f573e32d0b788867a783e9b013b94a4f3029d83a Mon Sep 17 00:00:00 2001 From: John Fredriksson <94405030+jfred9@users.noreply.github.com> Date: Fri, 3 Dec 2021 23:56:51 +0100 Subject: [PATCH] bar: Fix crash when unplugging HDMI There is a double delete situation which causes a SIGSEGV to happen during destruction of bar. This was introduced by the group feature patch. The same object pointer is stored in two different vectors of unique_ptr element. Replace with shared_ptr to handle reference counting correctly and avoid double delete. --- include/bar.hpp | 8 ++++---- src/bar.cpp | 9 +++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/bar.hpp b/include/bar.hpp index 4aa17c17..01a9d034 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -112,14 +112,14 @@ class Bar { Gtk::Box center_; Gtk::Box right_; Gtk::Box box_; - std::vector> modules_left_; - std::vector> modules_center_; - std::vector> modules_right_; + std::vector> modules_left_; + std::vector> modules_center_; + std::vector> modules_right_; #ifdef HAVE_SWAY using BarIpcClient = modules::sway::BarIpcClient; std::unique_ptr _ipc_client; #endif - std::vector> modules_all_; + std::vector> modules_all_; }; } // namespace waybar diff --git a/src/bar.cpp b/src/bar.cpp index fbd4623f..133c29aa 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -735,18 +735,19 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos, Gtk module = factory.makeModule(ref); } - modules_all_.emplace_back(module); + std::shared_ptr module_sp(module); + modules_all_.emplace_back(module_sp); if (group) { group->pack_start(*module, false, false); } else { if (pos == "modules-left") { - modules_left_.emplace_back(module); + modules_left_.emplace_back(module_sp); } if (pos == "modules-center") { - modules_center_.emplace_back(module); + modules_center_.emplace_back(module_sp); } if (pos == "modules-right") { - modules_right_.emplace_back(module); + modules_right_.emplace_back(module_sp); } } module->dp.connect([module, &name] {