Fix the bug that open file error

we should close fds after using,
otherwise we will use up them.