Fix memory leak in branch