From 40b5d2812cadb704ee6630fb9a7acbfeb5c9e457 Mon Sep 17 00:00:00 2001 From: "andrey.bychkov" Date: Thu, 6 Aug 2026 10:18:40 +0300 Subject: [PATCH] fix(PISharedMemory): reset data and unlink on mmap failure When mmap() returned MAP_FAILED, data stayed as (void*)-1, causing subsequent read/write/close to pass the null guard and crash. Now resets data=nullptr, and calls shm_unlink when owner=true to avoid orphaned shared memory objects. --- libs/main/io_devices/pisharedmemory.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/main/io_devices/pisharedmemory.cpp b/libs/main/io_devices/pisharedmemory.cpp index c50ea67d..6577b5dc 100644 --- a/libs/main/io_devices/pisharedmemory.cpp +++ b/libs/main/io_devices/pisharedmemory.cpp @@ -144,6 +144,9 @@ bool PISharedMemory::openDevice() { ::close(fd); if (PRIVATE->data == MAP_FAILED) { piCoutObj << "mmap error," << errorString(); + if (PRIVATE->owner) shm_unlink((const char *)PRIVATE->name.data()); + PRIVATE->data = nullptr; + PRIVATE->owner = false; return false; } // piCoutObj << "opened" << PRIVATE->data;