close fd on error