On Thu, 19 Jun 2025 at 07:37, Alvaro Falagan <alvarofalaga...@gmail.com> wrote:
> Bash does not clean up all its internal memory and leaves at least one file > descriptor (`/dev/pts/0`, fd 255) open at exit. Why would it be a problem if memory is still allocated or filedescriptors are still open at exit? Memory pages and filedescriptors are per-process kernel resources, so they cannot persist beyond the process that they're part of, so it would be redundant to deallocate memory or close filedescriptors immediately before exiting. Similarly, memory pages are also deallocated upon execve, so deallocating memory would be equally pointless there. Just because valgrind says "leak" does not mean there really is a leak, just that there *might* be one. Bash normally keeps fd#255 (or some other number depending on the build configuration) open on its /dev/tty, or its original stderr, if that was a tty. As far as I know this isn't affected by pipelines or heredocs. Do you have some indication that this is handled differently in a pipeline or with a heredoc, in a way that actually matters? -Martin PS: If you're on Linux, try: ls -Ul /proc/$$/fd You can make some very strange things happen by going: exec 255>&-