Fixing memory leak in test case