diff --git a/src/util/mpz.h b/src/util/mpz.h index 8f9548462..9e047929c 100644 --- a/src/util/mpz.h +++ b/src/util/mpz.h @@ -299,6 +299,7 @@ class mpz_manager { void set_i64(mpz & c, int64_t v) { if (v >= INT_MIN && v <= INT_MAX) { + deallocate(c); // Free any existing large value before setting small c.set(static_cast(v)); } else { @@ -589,6 +590,7 @@ public: void set(mpz & target, mpz const & source) { if (is_small(source)) { + deallocate(target); // Free any existing large value before setting small target.set(source.value()); } else { @@ -597,6 +599,7 @@ public: } void set(mpz & a, int val) { + deallocate(a); // Free any existing large value before setting small a.set(val); } @@ -615,6 +618,7 @@ public: void set(mpz & a, uint64_t val) { if (val < INT_MAX) { + deallocate(a); // Free any existing large value before setting small a.set(static_cast(val)); } else {