[Bf-blender-cvs] [48d8aa74847] master: Fix failure to clear DND in_use in rare cases under Wayland

Campbell Barton noreply at git.blender.org
Fri Oct 28 03:41:00 CEST 2022


Commit: 48d8aa74847231700db8154320d058e82fe7df4a
Author: Campbell Barton
Date:   Fri Oct 28 12:34:26 2022 +1100
Branches: master
https://developer.blender.org/rB48d8aa74847231700db8154320d058e82fe7df4a

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.

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

M	intern/ghost/intern/GHOST_SystemWayland.cpp

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

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;
 }



More information about the Bf-blender-cvs mailing list