haiku: check for filehandle before closing