diff --git a/xpra/client/gui/window_backing_base.py b/xpra/client/gui/window_backing_base.py index 6557ba92be..8814abaf77 100644 --- a/xpra/client/gui/window_backing_base.py +++ b/xpra/client/gui/window_backing_base.py @@ -911,7 +911,8 @@ def paint_mmap(self, img_data, x: int, y: int, width: int, height: int, rowstrid """ must be called from UI thread see _mmap_send() in seamless.py for details """ assert self.mmap_enabled - data = mmap_read(self.mmap, *img_data) + data, free_cb = mmap_read(self.mmap, *img_data) + callbacks.append(free_cb) rgb_format = options.strget("rgb_format", "RGB") # Note: BGR(A) is only handled by gl.backing x, y = self.gravity_adjust(x, y, options) diff --git a/xpra/net/mmap.py b/xpra/net/mmap.py index d441b124ff..2e373ce39b 100644 --- a/xpra/net/mmap.py +++ b/xpra/net/mmap.py @@ -7,9 +7,9 @@ import sys from ctypes import c_ubyte, c_uint32 from typing import Any -from collections.abc import ByteString +from collections.abc import ByteString, Callable -from xpra.common import roundup +from xpra.common import roundup, noop from xpra.util.env import envbool, shellsub from xpra.os_util import get_group_id, WIN32, POSIX from xpra.scripts.config import FALSE_OPTIONS @@ -268,7 +268,7 @@ def int_from_buffer(mmap_area, pos: int) -> c_uint32: # descr_data is a list of (offset, length) # areas from the mmap region -def mmap_read(mmap_area, *descr_data) -> ByteString: +def mmap_read(mmap_area, *descr_data) -> tuple[ByteString, Callable]: """ Reads data from the mmap_area as written by 'mmap_write'. The descr_data is the list of mmap chunks used. @@ -278,14 +278,15 @@ def mmap_read(mmap_area, *descr_data) -> ByteString: if len(descr_data) == 1: # construct an array directly from the mmap zone: offset, length = descr_data[0] - data_start.value = offset + length - return (mv[offset:offset + length]).toreadonly() + def free_mem(*_args): + data_start.value = offset + length + return (mv[offset:offset + length]).toreadonly(), free_mem # re-construct the buffer from discontiguous chunks: data = [] for offset, length in descr_data: data.append(mv[offset:offset + length]) data_start.value = offset + length - return b"".join(data) + return b"".join(data), noop def mmap_write(mmap_area, mmap_size: int, data):