fix some file pointer/descriptor leaks