Fixed memory leak (which triggered asserts in tests)