Skip to content

Commit 8f14263

Browse files
committed
TaskQueue: Add destructor to close FDs, preventing resource leak
The `Task` class was missing a destructor to close pipe file descriptors when destroyed. This caused file descriptor exhaustion after ~2,187 test runs, making tests fail with POLLNVAL errors when the system ran out of resources. This was found with: ``` ./unittests/Basic/SwiftBasicTests --gtest_filter="TaskQueueTest.*" --gtest_repeat=1000 ```
1 parent 3dcfdaf commit 8f14263

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/Basic/Unix/TaskQueue.inc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ public:
114114
"Env must either be empty or null-terminated!");
115115
}
116116

117+
~Task() {
118+
// Ensure pipes are closed when the task is destroyed
119+
if (Pipe >= 0) {
120+
close(Pipe);
121+
Pipe = -1;
122+
}
123+
if (ErrorPipe >= 0) {
124+
close(ErrorPipe);
125+
ErrorPipe = -1;
126+
}
127+
}
128+
117129
const char *getExecPath() const { return ExecPath; }
118130
ArrayRef<const char *> getArgs() const { return Args; }
119131
StringRef getOutput() const { return Output; }

0 commit comments

Comments
 (0)