Pty fix 2

Fix goroutines/fds leaks in TTY mode.

This issue was that the /dev/ptmx fd was never closed within the child, so the pipe's goroutine could never finish.

The issue was already present in master, I added a unit test for this scenario.