diff options
author | Campbell Barton <campbell@blender.org> | 2022-10-28 04:34:26 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-10-28 04:37:44 +0300 |
commit | 48d8aa74847231700db8154320d058e82fe7df4a (patch) | |
tree | 74a0389d93e72b6c3300ba7269711fe663301632 /intern | |
parent | 586d9214b75b070bc37d06860be62404974dba91 (diff) |
Fix failure to clear DND in_use in rare cases under Wayland
If opening a pipe failed, 'data_offer->dnd.in_use' wasn't cleared.
Avoid early return where it duplicates logic in an error prone way.
Diffstat (limited to 'intern')
-rw-r--r-- | intern/ghost/intern/GHOST_SystemWayland.cpp | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp index 72a9b5beef1..86b7a0f25f6 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.cpp +++ b/intern/ghost/intern/GHOST_SystemWayland.cpp @@ -1672,15 +1672,14 @@ static char *read_buffer_from_data_offer(GWL_DataOffer *data_offer, size_t *r_len) { int pipefd[2]; - if (UNLIKELY(pipe(pipefd) != 0)) { + const bool pipefd_ok = pipe(pipefd) == 0; + if (pipefd_ok) { + wl_data_offer_receive(data_offer->id, mime_receive, pipefd[1]); + close(pipefd[1]); + } + else { 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]); - close(pipefd[1]); /* Only for DND (A no-op to disable for clipboard data-offer). */ data_offer->dnd.in_use = false; @@ -1689,9 +1688,11 @@ static char *read_buffer_from_data_offer(GWL_DataOffer *data_offer, mutex->unlock(); } /* WARNING: `data_offer` may be freed from now on. */ - - char *buf = read_file_as_buffer(pipefd[0], nil_terminate, r_len); - close(pipefd[0]); + char *buf = nullptr; + if (pipefd_ok) { + buf = read_file_as_buffer(pipefd[0], nil_terminate, r_len); + close(pipefd[0]); + } return buf; } @@ -1702,22 +1703,24 @@ static char *read_buffer_from_primary_selection_offer(GWL_PrimarySelection_DataO size_t *r_len) { int pipefd[2]; - if (UNLIKELY(pipe(pipefd) != 0)) { + const bool pipefd_ok = pipe(pipefd) == 0; + if (pipefd_ok) { + zwp_primary_selection_offer_v1_receive(data_offer->id, mime_receive, pipefd[1]); + close(pipefd[1]); + } + else { 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]); - close(pipefd[1]); if (mutex) { mutex->unlock(); } /* WARNING: `data_offer` may be freed from now on. */ - char *buf = read_file_as_buffer(pipefd[0], nil_terminate, r_len); - close(pipefd[0]); + char *buf = nullptr; + if (pipefd_ok) { + buf = read_file_as_buffer(pipefd[0], nil_terminate, r_len); + close(pipefd[0]); + } return buf; } |