mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
fix(sway): resolve destruction dependency between Ipc and SleeperThread
Ipc destructor closes socket and thus wakes up SleeperThread which was waiting for socket data in Ipc::handleEvent. Ipc::handleEvent then proceeds with sending signal to already destroyed object, causing heap-use-after-free Address Sanitizer error.
This commit is contained in:
@ -10,19 +10,23 @@ Ipc::Ipc() {
|
||||
}
|
||||
|
||||
Ipc::~Ipc() {
|
||||
// To fail the IPC header
|
||||
write(fd_, "close-sway-ipc", 14);
|
||||
write(fd_event_, "close-sway-ipc", 14);
|
||||
thread_.stop();
|
||||
|
||||
if (fd_ > 0) {
|
||||
// To fail the IPC header
|
||||
write(fd_, "close-sway-ipc", 14);
|
||||
close(fd_);
|
||||
fd_ = -1;
|
||||
}
|
||||
if (fd_event_ > 0) {
|
||||
write(fd_event_, "close-sway-ipc", 14);
|
||||
close(fd_event_);
|
||||
fd_event_ = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void Ipc::setWorker(std::function<void()>&& func) { thread_ = func; }
|
||||
|
||||
const std::string Ipc::getSocketPath() const {
|
||||
const char* env = getenv("SWAYSOCK");
|
||||
if (env != nullptr) {
|
||||
|
@ -8,7 +8,13 @@ Mode::Mode(const std::string& id, const Json::Value& config)
|
||||
ipc_.subscribe(R"(["mode"])");
|
||||
ipc_.signal_event.connect(sigc::mem_fun(*this, &Mode::onEvent));
|
||||
// Launch worker
|
||||
worker();
|
||||
ipc_.setWorker([this] {
|
||||
try {
|
||||
ipc_.handleEvent();
|
||||
} catch (const std::exception& e) {
|
||||
spdlog::error("Mode: {}", e.what());
|
||||
}
|
||||
});
|
||||
dp.emit();
|
||||
}
|
||||
|
||||
@ -31,16 +37,6 @@ void Mode::onEvent(const struct Ipc::ipc_response& res) {
|
||||
}
|
||||
}
|
||||
|
||||
void Mode::worker() {
|
||||
thread_ = [this] {
|
||||
try {
|
||||
ipc_.handleEvent();
|
||||
} catch (const std::exception& e) {
|
||||
spdlog::error("Mode: {}", e.what());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
auto Mode::update() -> void {
|
||||
if (mode_.empty()) {
|
||||
event_box_.hide();
|
||||
|
@ -11,7 +11,13 @@ Window::Window(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||
// Get Initial focused window
|
||||
getTree();
|
||||
// Launch worker
|
||||
worker();
|
||||
ipc_.setWorker([this] {
|
||||
try {
|
||||
ipc_.handleEvent();
|
||||
} catch (const std::exception& e) {
|
||||
spdlog::error("Window: {}", e.what());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void Window::onEvent(const struct Ipc::ipc_response& res) { getTree(); }
|
||||
@ -28,16 +34,6 @@ void Window::onCmd(const struct Ipc::ipc_response& res) {
|
||||
}
|
||||
}
|
||||
|
||||
void Window::worker() {
|
||||
thread_ = [this] {
|
||||
try {
|
||||
ipc_.handleEvent();
|
||||
} catch (const std::exception& e) {
|
||||
spdlog::error("Window: {}", e.what());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
auto Window::update() -> void {
|
||||
if (!old_app_id_.empty()) {
|
||||
bar_.window.get_style_context()->remove_class(old_app_id_);
|
||||
|
@ -22,7 +22,13 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
|
||||
window.signal_scroll_event().connect(sigc::mem_fun(*this, &Workspaces::handleScroll));
|
||||
}
|
||||
// Launch worker
|
||||
worker();
|
||||
ipc_.setWorker([this] {
|
||||
try {
|
||||
ipc_.handleEvent();
|
||||
} catch (const std::exception &e) {
|
||||
spdlog::error("Workspaces: {}", e.what());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void Workspaces::onEvent(const struct Ipc::ipc_response &res) {
|
||||
@ -102,16 +108,6 @@ void Workspaces::onCmd(const struct Ipc::ipc_response &res) {
|
||||
}
|
||||
}
|
||||
|
||||
void Workspaces::worker() {
|
||||
thread_ = [this] {
|
||||
try {
|
||||
ipc_.handleEvent();
|
||||
} catch (const std::exception &e) {
|
||||
spdlog::error("Workspaces: {}", e.what());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
bool Workspaces::filterButtons() {
|
||||
bool needReorder = false;
|
||||
for (auto it = buttons_.begin(); it != buttons_.end();) {
|
||||
|
Reference in New Issue
Block a user