Skip to content

Commit

Permalink
Unlink shm file on close
Browse files Browse the repository at this point in the history
  • Loading branch information
HazardousPeach committed Sep 23, 2024
1 parent d8d8b5a commit 045966d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Source/Core/Common/MemArena.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MemArena final
///
void GrabSHMSegment(size_t size, std::string_view base_name);

///
//
/// Release the memory segment previously allocated with GrabSHMSegment().
/// Should not be called before all views have been released.
///
Expand Down 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
5 changes: 3 additions & 2 deletions Source/Core/Common/MemArenaUnix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ 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));
Expand All @@ -43,6 +43,7 @@ void MemArena::GrabSHMSegment(size_t size, std::string_view base_name)

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

Expand Down

0 comments on commit 045966d

Please sign in to comment.