invoke closedir after invoke opendir
closedir when succeed
Merge pull request #9401 from minggo/iss9398-not-close-dir

invoke closedir after invoke opendir