fixed some potential file descriptor leaks

fixed some potential file descriptor leaks