trace: fix potential use-after-free occurence