Resolve memory leak in path finding