From b544d989d1535705cfd77312829bf6d09394ea5f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 28 Oct 2022 09:29:00 +1100 Subject: GHOST/Wayland: unlock clipboard mutex on failure When the Wayland pipe can't be opened, don't leave the mutex locked. Also skip checking wl_data_device_manager when reading from the primary clipboard. --- intern/ghost/intern/GHOST_SystemWayland.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp index 0f609395124..36894807e73 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.cpp +++ b/intern/ghost/intern/GHOST_SystemWayland.cpp @@ -1681,6 +1681,9 @@ static const char *read_buffer_from_data_offer(GWL_DataOffer *data_offer, int pipefd[2]; if (UNLIKELY(pipe(pipefd) != 0)) { CLOG_WARN(LOG, "error creating pipe: %s", std::strerror(errno)); + if (mutex) { + mutex->unlock(); + } return nullptr; } wl_data_offer_receive(data_offer->id, mime_receive, pipefd[1]); @@ -1707,6 +1710,9 @@ static const char *read_buffer_from_primary_selection_offer( int pipefd[2]; if (UNLIKELY(pipe(pipefd) != 0)) { CLOG_WARN(LOG, "error creating pipe: %s", std::strerror(errno)); + if (mutex) { + mutex->unlock(); + } return nullptr; } zwp_primary_selection_offer_v1_receive(data_offer->id, mime_receive, pipefd[1]); @@ -5114,6 +5120,9 @@ static void system_clipboard_put_primary_selection(GWL_Display *display, const c static void system_clipboard_put(GWL_Display *display, const char *buffer) { + if (!display->wl_data_device_manager) { + return; + } GWL_Seat *seat = display->seats[0]; std::lock_guard lock{seat->data_source_mutex}; @@ -5140,7 +5149,7 @@ static void system_clipboard_put(GWL_Display *display, const char *buffer) void GHOST_SystemWayland::putClipboard(const char *buffer, bool selection) const { - if (UNLIKELY(!display_->wl_data_device_manager || display_->seats.empty())) { + if (UNLIKELY(display_->seats.empty())) { return; } -- cgit v1.2.3