summaryrefslogtreecommitdiff
path: root/ledger.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2004-08-19 03:28:48 -0400
committerJohn Wiegley <johnw@newartisans.com>2004-08-19 03:28:48 -0400
commitbf923ab33e9951d25611cb7193d6852e9113d929 (patch)
tree0c1f3b6367b42569ecfb297a5e3968fab742ac15 /ledger.cc
parent965e1fc28f725e830a6f51a5d41e7a3850d15b12 (diff)
downloadfork-ledger-bf923ab33e9951d25611cb7193d6852e9113d929.tar.gz
fork-ledger-bf923ab33e9951d25611cb7193d6852e9113d929.tar.bz2
fork-ledger-bf923ab33e9951d25611cb7193d6852e9113d929.zip
use std::auto_ptr wherever a thrown exception might otherwise leak memory
Diffstat (limited to 'ledger.cc')
-rw-r--r--ledger.cc19
1 files changed, 10 insertions, 9 deletions
diff --git a/ledger.cc b/ledger.cc
index 11972d55..7432cb78 100644
--- a/ledger.cc
+++ b/ledger.cc
@@ -55,7 +55,8 @@ bool journal_t::remove_entry(entry_t * entry)
entry_t * journal_t::derive_entry(strings_list::iterator i,
strings_list::iterator end) const
{
- entry_t * added = new entry_t;
+ std::auto_ptr<entry_t> added(new entry_t);
+
entry_t * matching = NULL;
if (! parse_date((*i).c_str(), &added->date)) {
@@ -97,17 +98,17 @@ entry_t * journal_t::derive_entry(strings_list::iterator i,
m_xact = matching->transactions.front();
amount_t amt(*i++);
- first = xact = new transaction_t(added, m_xact->account, amt, amt);
+ first = xact = new transaction_t(added.get(), m_xact->account, amt, amt);
+ added->add_transaction(xact);
if (xact->amount.commodity->symbol.empty()) {
xact->amount.commodity = m_xact->amount.commodity;
xact->cost.commodity = m_xact->amount.commodity;
}
- added->add_transaction(xact);
m_xact = matching->transactions.back();
- xact = new transaction_t(added, m_xact->account,
+ xact = new transaction_t(added.get(), m_xact->account,
- first->amount, - first->amount);
added->add_transaction(xact);
@@ -149,12 +150,11 @@ entry_t * journal_t::derive_entry(strings_list::iterator i,
}
amount_t amt(*i++);
- transaction_t * xact = new transaction_t(added, acct, amt, amt);
+ transaction_t * xact = new transaction_t(added.get(), acct, amt, amt);
+ added->add_transaction(xact);
if (! xact->amount.commodity)
xact->amount.commodity = cmdty;
-
- added->add_transaction(xact);
}
if (i != end && std::string(*i++) == "-from" && i != end) {
@@ -169,12 +169,13 @@ entry_t * journal_t::derive_entry(strings_list::iterator i,
std::exit(1);
}
transaction_t * xact
- = new transaction_t(added, matching->transactions.back()->account);
+ = new transaction_t(added.get(),
+ matching->transactions.back()->account);
added->add_transaction(xact);
}
}
- return added;
+ return added.release();
}
int parse_journal_file(const std::string& path,