summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/amount.cc25
-rw-r--r--src/amount.h2
2 files changed, 18 insertions, 9 deletions
diff --git a/src/amount.cc b/src/amount.cc
index bfbb591e..829b31ef 100644
--- a/src/amount.cc
+++ b/src/amount.cc
@@ -87,13 +87,17 @@ struct amount_t::bigint_t : public supports_flags<>
shared_ptr<commodity_pool_t> amount_t::current_pool;
+bool amount_t::is_initialized = false;
+
void amount_t::initialize(shared_ptr<commodity_pool_t> pool)
{
- mpz_init(temp);
- mpq_init(tempq);
- mpfr_init(tempf);
- mpfr_init(tempfb);
-
+ if (! is_initialized) {
+ mpz_init(temp);
+ mpq_init(tempq);
+ mpfr_init(tempf);
+ mpfr_init(tempfb);
+ is_initialized = true;
+ }
current_pool = pool;
}
@@ -106,10 +110,13 @@ void amount_t::shutdown()
{
current_pool.reset();
- mpz_clear(temp);
- mpq_clear(tempq);
- mpfr_clear(tempf);
- mpfr_clear(tempfb);
+ if (is_initialized) {
+ mpz_clear(temp);
+ mpq_clear(tempq);
+ mpfr_clear(tempf);
+ mpfr_clear(tempfb);
+ is_initialized = false;
+ }
}
void amount_t::_copy(const amount_t& amt)
diff --git a/src/amount.h b/src/amount.h
index 4405e058..e4abeb0b 100644
--- a/src/amount.h
+++ b/src/amount.h
@@ -92,6 +92,8 @@ public:
@note Normally called by session_t::shutdown(). */
static void shutdown();
+ static bool is_initialized;
+
/** The amount's decimal precision. */
typedef uint_least16_t precision_t;