Fix memory leak in test