Fix use-after-free

Thanks to LebedevRI for spotting that in the clang output.