Some things I noticed while coding #3472 (moved) stuff:
In tor_spawn_background():
retval = pipe(stderr_pipe); if (-1 == retval) {
if pipe() fails, the file descriptors of pipe(stdout_pipe) above are never closed.
In the tor_check_port_forwarding() code or in the Windows version of tor_read_all_handle() the stdout/stderr handles are not CloseHandle()d on stream error.
I'll prepare a patch.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Child items
...
Show closed items
Linked items
0
Link issues together to show that they're related.
Learn more.
95df581c054595 looks okay, but I don't know about 859b279a5cf25. In 859b279a5cf25, it looks like we are only calling CloseHandle on that one path through log_from_handle, but we aren't closing it on the other paths. I would expect that either all paths should close it, or none should, or that the documentation would explain why that sometimes-close behavior was reasonable.
Hrm. I still think 95df581 is good to merge, but for the others, we should indeed have the caller close stuff as appropriate. Having a "read" function that sometimes closes the pipe doesn't make much sense.
Should I cherrypick the one commit I like at this point? Looking at log_from_pipe(), it looks like it doesn't fclose streams any more.
Hrm. I still think 95df581 is good to merge, but for the others, we should indeed have the caller close stuff as appropriate. Having a "read" function that sometimes closes the pipe doesn't make much sense.
Should I cherrypick the one commit I like at this point? Looking at log_from_pipe(), it looks like it doesn't fclose streams any more.
Aha! I see that your d6c18c5804f12f8f4428abce11fc47c64d2a0dd0 stopped fclose()ing the handles in log_from_pipe() for a good reason.
I guess the new question is, who calls tor_process_handle_destroy() on the child_handle created by the last tor_check_port_forwarding() call? I guess no one.
Do we care about this? If not, I'm all about closing this stupid ticket.
"this" being the resource leak that happens if nobody calls the destroy function? I do in fact care about resource leaks, if I understand you correctly.
"this" being the resource leak that happens if nobody calls the destroy function? I do in fact care about resource leaks, if I understand you correctly.
tor_check_port_forwarding() is called periodically. The last time it is called before Tor termination process_handle_destroy() is not called on the child_handle. This leaks the process_handle_t and two file descriptors upon Tor termination. It's not a resource leak that stacks up.
The logic of tor_check_port_forwarding() is not very welcoming to fixes either; it does too many things. Maybe exposing child_handle as a file-level static variable (renamed as port_fw_child_handle) and proving a port_forwarding_free_all() function be called upon shutdown could help... Still, that fix is kinda messy.