Bug/5493 avoid file descriptor leaks