Fixed bugs that may leak fd in exception flow