get_shallow_commits: Avoid memory leak if a commit has been reached already.