summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.cc14
1 files changed, 10 insertions, 4 deletions
diff --git a/main.cc b/main.cc
index 30eb2794..8be24935 100644
--- a/main.cc
+++ b/main.cc
@@ -22,8 +22,8 @@
using namespace ledger;
-int parse_and_report(config_t& config, report_t& report,
- int argc, char * argv[], char * envp[])
+int parse_and_report(config_t& config, std::auto_ptr<journal_t>& journal,
+ report_t& report, int argc, char * argv[], char * envp[])
{
// Configure the terminus for value expressions
@@ -144,7 +144,7 @@ int parse_and_report(config_t& config, report_t& report,
// Parse initialization files, ledger data, price database, etc.
- std::auto_ptr<journal_t> journal(new journal_t);
+ journal.reset(new journal_t);
{ TRACE_PUSH(parser, "Parsing journal file");
@@ -440,6 +440,12 @@ appending the output of this command to your Ledger file if you so choose."
int main(int argc, char * argv[], char * envp[])
{
+ // This variable must be defined here so that any memory it holds is still
+ // available should the subsequent exception handlers catch an inner
+ // exception and need to report something on the invalid state of the
+ // journal (such as an unbalanced entry).
+ std::auto_ptr<journal_t> journal;
+
try {
#if DEBUG_LEVEL < BETA
ledger::do_cleanup = false;
@@ -449,7 +455,7 @@ int main(int argc, char * argv[], char * envp[])
ledger::config = &config;
ledger::report = &report;
TRACE_PUSH(main, "Ledger starting");
- int status = parse_and_report(config, report, argc, argv, envp);
+ int status = parse_and_report(config, journal, report, argc, argv, envp);
TRACE_POP(main, "Ledger done");
return status;
}