tests/plugins: fix use-after-free bug