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:
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user