Skip to content
This repository has been archived by the owner on Apr 19, 2021. It is now read-only.

Commit

Permalink
Cleanup RAM allocated by concatenated files.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbenden committed May 9, 2018
1 parent 86e7812 commit d9d3c84
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/u-lang/Basic/VirtualFileSystem.hpp
Expand Up @@ -471,9 +471,13 @@ class ConcatenatedOverlayFileSystem : public FileSystem
/// their addition.
FileSystemList FSList;

std::vector<void*> Cleanup;

public:
explicit ConcatenatedOverlayFileSystem(IntrusiveRefCntPtr<FileSystem> Base);

~ConcatenatedOverlayFileSystem();

/// \brief Pushes a file system on top of the stack.
void pushOverlay(IntrusiveRefCntPtr<FileSystem> FS);

Expand Down
10 changes: 10 additions & 0 deletions lib/Basic/VirtualFileSystem.cpp
Expand Up @@ -932,6 +932,14 @@ ConcatenatedOverlayFileSystem::ConcatenatedOverlayFileSystem(IntrusiveRefCntPtr<
FSList.push_back(std::move(BaseFS));
}

ConcatenatedOverlayFileSystem::~ConcatenatedOverlayFileSystem()
{
for (auto item : Cleanup)
{
delete reinterpret_cast<detail::InMemoryFile*>(item);
}
}

void
ConcatenatedOverlayFileSystem::pushOverlay(IntrusiveRefCntPtr<FileSystem> FS)
{
Expand Down Expand Up @@ -1018,6 +1026,8 @@ ConcatenatedOverlayFileSystem::openFileForRead(const llvm::Twine& Path)

auto* F = new detail::InMemoryFile(std::move(Stat), std::move(memoryBuffer));

Cleanup.push_back(F);

return std::unique_ptr<File>(new detail::InMemoryFileAdaptor(*F));
}

Expand Down

0 comments on commit d9d3c84

Please sign in to comment.