diff options
| author | David Blaikie <dblaikie@gmail.com> | 2014-07-08 15:46:02 +0000 |
|---|---|---|
| committer | David Blaikie <dblaikie@gmail.com> | 2014-07-08 15:46:02 +0000 |
| commit | 87e7bf9da1bac263ba7645ebf64447afae4db9d1 (patch) | |
| tree | d21ccba9ba14bb78c79c5c1438d65525c8214791 /lib/Basic/FileSystemStatCache.cpp | |
| parent | 6f64411e4bfec719412c0af86aa5ef6a0104ec10 (diff) | |
Improve memory ownership of vfs::Files in the FileSystemStatCache by using std::unique_ptr
Spotted after a memory leak (due to the complexities of manual memory
management) was fixed in 212466.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@212541 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic/FileSystemStatCache.cpp')
| -rw-r--r-- | lib/Basic/FileSystemStatCache.cpp | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/lib/Basic/FileSystemStatCache.cpp b/lib/Basic/FileSystemStatCache.cpp index 4952ef49ef..7515cfb440 100644 --- a/lib/Basic/FileSystemStatCache.cpp +++ b/lib/Basic/FileSystemStatCache.cpp @@ -52,8 +52,8 @@ static void copyStatusToFileData(const vfs::Status &Status, /// implementation can optionally fill in FileDescriptor with a valid /// descriptor and the client guarantees that it will close it. bool FileSystemStatCache::get(const char *Path, FileData &Data, bool isFile, - vfs::File **F, FileSystemStatCache *Cache, - vfs::FileSystem &FS) { + std::unique_ptr<vfs::File> *F, + FileSystemStatCache *Cache, vfs::FileSystem &FS) { LookupResult R; bool isForDir = !isFile; @@ -92,7 +92,7 @@ bool FileSystemStatCache::get(const char *Path, FileData &Data, bool isFile, if (Status) { R = CacheExists; copyStatusToFileData(*Status, Data); - *F = OwnedFile.release(); + *F = std::move(OwnedFile); } else { // fstat rarely fails. If it does, claim the initial open didn't // succeed. @@ -109,11 +109,8 @@ bool FileSystemStatCache::get(const char *Path, FileData &Data, bool isFile, // demands. if (Data.IsDirectory != isForDir) { // If not, close the file if opened. - if (F && *F) { - (*F)->close(); - delete *F; + if (F) *F = nullptr; - } return true; } @@ -123,7 +120,7 @@ bool FileSystemStatCache::get(const char *Path, FileData &Data, bool isFile, MemorizeStatCalls::LookupResult MemorizeStatCalls::getStat(const char *Path, FileData &Data, bool isFile, - vfs::File **F, vfs::FileSystem &FS) { + std::unique_ptr<vfs::File> *F, vfs::FileSystem &FS) { LookupResult Result = statChained(Path, Data, isFile, F, FS); // Do not cache failed stats, it is easy to construct common inconsistent |
