fixed a rather obscure memory bug, which also simplified some code
This commit is contained in:
parent
3038b7cee8
commit
c5d519447e
4 changed files with 13 additions and 43 deletions
33
amount.cc
33
amount.cc
|
|
@ -84,33 +84,6 @@ _init_amounts::~_init_amounts()
|
||||||
true_value.ref--;
|
true_value.ref--;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clean_commodity_history(char * item_pool, char * item_pool_end)
|
|
||||||
{
|
|
||||||
for (commodities_map::iterator i = commodity_t::commodities.begin();
|
|
||||||
i != commodity_t::commodities.end();
|
|
||||||
i++)
|
|
||||||
for (history_map::iterator j = (*i).second->history.begin();
|
|
||||||
j != (*i).second->history.end();
|
|
||||||
j++) {
|
|
||||||
amount_t::bigint_t * quantity = (*j).second.quantity;
|
|
||||||
if (quantity &&
|
|
||||||
(char *)quantity >= item_pool &&
|
|
||||||
(char *)quantity < item_pool_end) {
|
|
||||||
assert(quantity->flags & BIGINT_BULK_ALLOC);
|
|
||||||
|
|
||||||
// Since the journal in which this price was bulk alloc'd (on
|
|
||||||
// reading from a binary file) is going away, we must make a
|
|
||||||
// new copy of the value, because other journals might still
|
|
||||||
// be using it.
|
|
||||||
|
|
||||||
amount_t::bigint_t * q = new amount_t::bigint_t(*quantity);
|
|
||||||
if (--quantity->ref == 0)
|
|
||||||
quantity->~bigint_t();
|
|
||||||
(*j).second.quantity = q;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mpz_round(mpz_t out, mpz_t value, int value_prec, int round_prec)
|
static void mpz_round(mpz_t out, mpz_t value, int value_prec, int round_prec)
|
||||||
{
|
{
|
||||||
// Round `value', with an encoding precision of `value_prec', to a
|
// Round `value', with an encoding precision of `value_prec', to a
|
||||||
|
|
@ -238,9 +211,15 @@ void amount_t::_copy(const amount_t& amt)
|
||||||
if (quantity)
|
if (quantity)
|
||||||
_release();
|
_release();
|
||||||
|
|
||||||
|
// Never maintain a pointer into a bulk allocation pool; such
|
||||||
|
// pointers are not guaranteed to remain.
|
||||||
|
if (amt.quantity->flags & BIGINT_BULK_ALLOC) {
|
||||||
|
quantity = new bigint_t(*amt.quantity);
|
||||||
|
} else {
|
||||||
quantity = amt.quantity;
|
quantity = amt.quantity;
|
||||||
quantity->ref++;
|
quantity->ref++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
commodity_ = amt.commodity_;
|
commodity_ = amt.commodity_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -354,8 +354,6 @@ bool account_t::valid() const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clean_commodity_history(char * item_pool, char * item_pool_end);
|
|
||||||
|
|
||||||
journal_t::~journal_t()
|
journal_t::~journal_t()
|
||||||
{
|
{
|
||||||
DEBUG_PRINT("ledger.memory.dtors", "dtor journal_t");
|
DEBUG_PRINT("ledger.memory.dtors", "dtor journal_t");
|
||||||
|
|
@ -374,9 +372,6 @@ journal_t::~journal_t()
|
||||||
else
|
else
|
||||||
(*i)->~entry_t();
|
(*i)->~entry_t();
|
||||||
|
|
||||||
// Remove historical prices which were allocated in the item_pool.
|
|
||||||
clean_commodity_history(item_pool, item_pool_end);
|
|
||||||
|
|
||||||
if (item_pool)
|
if (item_pool)
|
||||||
delete[] item_pool;
|
delete[] item_pool;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
5
main.cc
5
main.cc
|
|
@ -305,14 +305,9 @@ int parse_and_report(int argc, char * argv[], char * envp[])
|
||||||
|
|
||||||
if (config.use_cache && config.cache_dirty &&
|
if (config.use_cache && config.cache_dirty &&
|
||||||
! config.cache_file.empty()) {
|
! config.cache_file.empty()) {
|
||||||
if (access(config.cache_file.c_str(), W_OK) == -1) {
|
|
||||||
std::cerr << "Warning: Cannot update cache file '"
|
|
||||||
<< config.cache_file << "'" << std::endl;
|
|
||||||
} else {
|
|
||||||
std::ofstream stream(config.cache_file.c_str());
|
std::ofstream stream(config.cache_file.c_str());
|
||||||
write_binary_journal(stream, journal.get(), &journal->sources);
|
write_binary_journal(stream, journal.get(), &journal->sources);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
5
main.py
5
main.py
|
|
@ -87,10 +87,11 @@ else:
|
||||||
text_parser = TextualParser ()
|
text_parser = TextualParser ()
|
||||||
bin_parser = BinaryParser ()
|
bin_parser = BinaryParser ()
|
||||||
qif_parser = QifParser ()
|
qif_parser = QifParser ()
|
||||||
|
gnucash_parser = None
|
||||||
try:
|
try:
|
||||||
gnucush_parser = GnucashParser ()
|
gnucash_parser = GnucashParser ()
|
||||||
except:
|
except:
|
||||||
gnucush_parser = None
|
pass
|
||||||
|
|
||||||
register_parser (text_parser)
|
register_parser (text_parser)
|
||||||
register_parser (bin_parser)
|
register_parser (bin_parser)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue