Close possible fd leaks on error conditions