fixed BFS memory leak