Move freeing of topbuild later to prevent use-after-free