mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-29 06:13:20 +00:00
Fix undefined behavior in closing a moved pipe
`pipe_next_read` is moved in the body of the loop, and not re-initialized the last go around. However, we call `pipe_next_read.close()` after the loop, which is undefined behavior (as it's been moved). Best case scenario, the compiler passed the address of our copy of the struct to `exec_process_in_job` and beyond, it went out of scope there, the value of `fd` was set to closed (minus one), and we explicitly call `.close()` again, in which case it does nothing. Worst case scenario, the compiler re-uses the storage for the now-moved struct for something else and our call to `.close()` ends up closing some other value of `fd` (valid or invalid) and things break. Aside from the fact that we obviously don't need to close it since it's not assigned for the last process in the job, it's a RAII object so we don't have to worry about manually closing it in the first place.
This commit is contained in:
parent
57615504d0
commit
c014c23662
1 changed files with 0 additions and 1 deletions
|
@ -1093,7 +1093,6 @@ bool exec_job(parser_t &parser, const shared_ptr<job_t> &j, const io_chain_t &bl
|
|||
}
|
||||
procs_launched += 1;
|
||||
}
|
||||
pipe_next_read.close();
|
||||
|
||||
// If our pipeline was aborted before any process was successfully launched, then there is
|
||||
// nothing to reap, and we can perform an early return.
|
||||
|
|
Loading…
Reference in a new issue