Fixed memory leak when running tests.