Skip to content

Commit 39d73ef

Browse files
benlangmuircachemeifyoucan
authored andcommitted
[llvm][cas] Prevent leak of lock file descriptor
We need to close the lock file so we don't leak file descriptors. This wasn't seen commonly because most operations only ever have a single CAS, but when forming many CompilerInvocations we can end up creating and destroying many CAS instances, and eventually run out of FDs. (cherry picked from commit 67cb825)
1 parent 15cbae6 commit 39d73ef

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

llvm/lib/CAS/UnifiedOnDiskCache.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,12 @@ bool UnifiedOnDiskCache::hasExceededSizeLimit() const {
266266
Error UnifiedOnDiskCache::close(bool CheckSizeLimit) {
267267
if (LockFD == -1)
268268
return Error::success(); // already closed.
269-
auto _1 = make_scope_exit([&]() { LockFD = -1; });
269+
auto _1 = make_scope_exit([&]() {
270+
assert(LockFD >= 0);
271+
sys::fs::file_t LockFile = sys::fs::convertFDToNativeFile(LockFD);
272+
sys::fs::closeFile(LockFile);
273+
LockFD = -1;
274+
});
270275

271276
bool ExceededSizeLimit = CheckSizeLimit ? hasExceededSizeLimit() : false;
272277
PrimaryKVDB.reset();

0 commit comments

Comments
 (0)