Added leaks checks to test command; fixed leaks in tests