fix segfaults when closing the current input port