Added memory leak check (with tests)