Test fails with SIGSEGV because of use-after-free