test: fix a potential memory leak