[llvm] [llvm-exegesis] Close file descriptors after use (PR #86584)

via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 25 14:33:17 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-tools-llvm-exegesis

Author: Aiden Grossman (boomanaiden154)

<details>
<summary>Changes</summary>

There are several insstances in the subprocess executor in llvm-exegesis where we fail to close file descriptors after using them. This leaves them open, which can cause issues later on if a third-party binary is using the exegesis libraries and executing many blocks before exiting. Leaving the descriptors open until process exit is also bad practice. This patch fixes that by explicitly calling close() when we are done with a specific file descriptor.

This patch fixes #<!-- -->86583.

---
Full diff: https://github.com/llvm/llvm-project/pull/86584.diff


2 Files Affected:

- (modified) llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp (+1) 
- (modified) llvm/tools/llvm-exegesis/lib/SubprocessMemory.cpp (+3) 


``````````diff
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index 498308e2edbe1f..7b01b8c69cdfb2 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -317,6 +317,7 @@ class SubProcessFunctionExecutorImpl
     int CounterFileDescriptor = Counter->getFileDescriptor();
     Error SendError =
         sendFileDescriptorThroughSocket(WriteFD, CounterFileDescriptor);
+    close(WriteFD);
 
     if (SendError)
       return SendError;
diff --git a/llvm/tools/llvm-exegesis/lib/SubprocessMemory.cpp b/llvm/tools/llvm-exegesis/lib/SubprocessMemory.cpp
index 1fd81bd407becb..06d589821071ad 100644
--- a/llvm/tools/llvm-exegesis/lib/SubprocessMemory.cpp
+++ b/llvm/tools/llvm-exegesis/lib/SubprocessMemory.cpp
@@ -50,6 +50,7 @@ Error SubprocessMemory::initializeSubprocessMemory(pid_t ProcessID) {
                                Twine(strerror(errno)));
   }
   SharedMemoryNames.push_back(AuxiliaryMemoryName);
+  close(AuxiliaryMemoryFD);
   return Error::success();
 }
 
@@ -87,6 +88,8 @@ Error SubprocessMemory::addMemoryDefinition(
           "Unmapping a memory definition in the parent failed: " +
           Twine(strerror(errno)));
     }
+
+    close(SharedMemoryFD);
   }
   return Error::success();
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/86584


More information about the llvm-commits mailing list