Fix memory leak in tests