From 5f472969cdc10e5b41f0f66502b2310ca39577b3 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 17 Jul 2008 20:03:50 -0400 Subject: Moved an auto_ptr up into main, since the memory it governs must still be available to the exception handlers that come immediately after it. --- main.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'main.cc') 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, + 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(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; + 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; } -- cgit v1.2.3