From b5d22a8134ac3bfc6c084b836729f4dd15e25bee Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 9 Jul 2022 22:27:26 +1000 Subject: 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.. --- intern/ghost/intern/GHOST_SystemWayland.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'intern') 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; } -- cgit v1.2.3