Fix use-after-free. Thanks ASAN for giving me a detailed report :-).