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.
This commit is contained in:
John Wiegley 2008-07-17 20:03:50 -04:00
parent d0669f8402
commit 5f472969cd

14
main.cc
View file

@ -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;
}