You should call `closedir()` before returning to save resources.