Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't unlink shared memory on Unix #13060

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Source/Core/Common/MemArena.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ class MemArena final
int m_shm_fd = 0;
void* m_reserved_region = nullptr;
std::size_t m_reserved_region_size = 0;
#ifndef ANDROID
std::string m_seg_name;
#endif
#endif
};

Expand Down
6 changes: 3 additions & 3 deletions Source/Core/Common/MemArenaUnix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ MemArena::~MemArena() = default;

void MemArena::GrabSHMSegment(size_t size, std::string_view base_name)
{
const std::string file_name = fmt::format("/{}.{}", base_name, getpid());
m_shm_fd = shm_open(file_name.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600);
m_seg_name = fmt::format("/{}.{}", base_name, getpid());
m_shm_fd = shm_open(m_seg_name.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600);
if (m_shm_fd == -1)
{
ERROR_LOG_FMT(MEMMAP, "shm_open failed: {}", strerror(errno));
return;
}
shm_unlink(file_name.c_str());
if (ftruncate(m_shm_fd, size) < 0)
ERROR_LOG_FMT(MEMMAP, "Failed to allocate low memory space");
}

void MemArena::ReleaseSHMSegment()
{
shm_unlink(m_seg_name.c_str());
close(m_shm_fd);
}

Expand Down