From 162498498110d61ab206dc20239d45e56191f0f8 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 14 Sep 2008 19:43:41 -0400 Subject: [PATCH] If an entry is being parsed but yields all null-amount transactions, completely ignore the entry. This is useful for supporting "safety" entries whose only purpose is to assert the balance of account(s) at a certain point in time. --- src/textual.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/textual.cc b/src/textual.cc index cc941695..39b1f55f 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -901,7 +901,7 @@ unsigned int textual_parser_t::parse(std::istream& in, pe->end_pos = end_pos; pe->end_line = linenum; } else { - throw new parse_error("Period entry failed to balance"); + throw parse_error("Period entry failed to balance"); } } break; @@ -978,17 +978,23 @@ unsigned int textual_parser_t::parse(std::istream& in, TRACE_START(entries, 1, "Time spent handling entries:"); if (entry_t * entry = parse_entry(in, line, account_stack.front(), *this, pos)) { + // The entry pointer is unowned at the minute, and there is a + // possibility that add_entry ma throw an exception, which + // would cause us to leak without this guard. + std::auto_ptr entry_ptr(entry); if (journal.add_entry(entry)) { + entry_ptr.release(); // it's owned by the journal now entry->src_idx = src_idx; entry->beg_pos = beg_pos; entry->beg_line = beg_line; entry->end_pos = pos; entry->end_line = linenum; count++; - } else { - checked_delete(entry); - throw parse_error("Entry does not balance"); } + // It's perfectly valid for the journal to reject the entry, + // which it will do if the entry has no substantive effect + // (for example, a checking entry, all of whose transactions + // have null amounts). } else { throw parse_error("Failed to parse entry"); }