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.
This commit is contained in:
2026-08-06 17:01:30 +03:00
committed by andrey
parent 9c3690d371
commit ef8fdb30f4
+3
View File
@@ -144,6 +144,9 @@ bool PISharedMemory::openDevice() {
::close(fd); ::close(fd);
if (PRIVATE->data == MAP_FAILED) { if (PRIVATE->data == MAP_FAILED) {
piCoutObj << "mmap error," << errorString(); piCoutObj << "mmap error," << errorString();
if (PRIVATE->owner) shm_unlink((const char *)PRIVATE->name.data());
PRIVATE->data = nullptr;
PRIVATE->owner = false;
return false; return false;
} }
// piCoutObj << "opened" << PRIVATE->data; // piCoutObj << "opened" << PRIVATE->data;