mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-19 08:22:45 +08:00
Ensure we don't leak half of a pipe
It was possible though unlikely for make_autoclose_pipes to close only one side of pipe, if it fails to find a new fd. This would result in an fd leak. Ensure that doesn't happen.
This commit is contained in:
parent
1cef87d790
commit
d1dab22691
15
src/io.cpp
15
src/io.cpp
|
@ -327,13 +327,18 @@ maybe_t<autoclose_pipes_t> make_autoclose_pipes(const fd_set_t &fdset) {
|
|||
set_cloexec(pipes[0]);
|
||||
set_cloexec(pipes[1]);
|
||||
|
||||
auto read = move_fd_to_unused(autoclose_fd_t{pipes[0]}, fdset);
|
||||
if (!read.valid()) return none();
|
||||
autoclose_fd_t read_end{pipes[0]};
|
||||
autoclose_fd_t write_end{pipes[1]};
|
||||
|
||||
auto write = move_fd_to_unused(autoclose_fd_t{pipes[1]}, fdset);
|
||||
if (!write.valid()) return none();
|
||||
// Ensure we have no conflicts.
|
||||
if (!fdset.empty()) {
|
||||
read_end = move_fd_to_unused(std::move(read_end), fdset);
|
||||
if (!read_end.valid()) return none();
|
||||
|
||||
return autoclose_pipes_t(std::move(read), std::move(write));
|
||||
write_end = move_fd_to_unused(std::move(write_end), fdset);
|
||||
if (!write_end.valid()) return none();
|
||||
}
|
||||
return autoclose_pipes_t(std::move(read_end), std::move(write_end));
|
||||
}
|
||||
|
||||
shared_ptr<const io_data_t> io_chain_t::io_for_fd(int fd) const {
|
||||
|
|
Loading…
Reference in New Issue
Block a user