fix some file descriptor leaks