Plug some mpz memory leaks and remove redundant copying