Fix potential leaks found by analyzer