Fix a memory leak in tests