fix: memory leaks in factorization