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.