Fix memory leak in path finding