[Bf-blender-cvs] [b5d22a8134a] master: Fix resource leaks setting custom cursors in Wayland

Campbell Barton noreply at git.blender.org
Sat Jul 9 14:48:12 CEST 2022


Commit: b5d22a8134ac3bfc6c084b836729f4dd15e25bee
Author: Campbell Barton
Date:   Sat Jul 9 22:27:26 2022 +1000
Branches: master
https://developer.blender.org/rBb5d22a8134ac3bfc6c084b836729f4dd15e25bee

Fix resource leaks setting custom cursors in Wayland

- Memory from the prior cursor was never un-mapped.
- posix_fallocate failure left a file handle open..

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

M	intern/ghost/intern/GHOST_SystemWayland.cpp

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

diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp
index 08aa640c5cd..76e5329a410 100644
--- a/intern/ghost/intern/GHOST_SystemWayland.cpp
+++ b/intern/ghost/intern/GHOST_SystemWayland.cpp
@@ -3347,6 +3347,11 @@ GHOST_TSuccess GHOST_SystemWayland::setCustomCursorShape(uint8_t *bitmap,
 
   cursor_t *cursor = &d->inputs[0]->cursor;
 
+  if (cursor->file_buffer->data) {
+    munmap(cursor->file_buffer->data, cursor->file_buffer->size);
+    cursor->file_buffer->data = nullptr;
+  }
+
   static const int32_t stride = sizex * 4; /* ARGB */
   cursor->file_buffer->size = (size_t)stride * sizey;
 
@@ -3376,6 +3381,7 @@ GHOST_TSuccess GHOST_SystemWayland::setCustomCursorShape(uint8_t *bitmap,
   }
 
   if (UNLIKELY(posix_fallocate(fd, 0, int32_t(cursor->file_buffer->size)) != 0)) {
+    close(fd);
     return GHOST_kFailure;
   }



More information about the Bf-blender-cvs mailing list