Ensure file descriptors are closed