Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Apr 26, 2024

Conversation

boomanaiden154
Copy link
Contributor

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.

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 llvm#86583.
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 25, 2024

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

Author: Aiden Grossman (boomanaiden154)

Changes

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 --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();
 }

Copy link

✅ With the latest revision this PR passed the Python code formatter.

Copy link

✅ With the latest revision this PR passed the C/C++ code formatter.

@boomanaiden154 boomanaiden154 merged commit 74a5e77 into llvm:main Apr 26, 2024
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[llvm-exegesis] Not closing file descriptors after use
4 participants