Fix memory leak in the test