diff options
author | John Wiegley <johnw@newartisans.com> | 2012-03-05 15:17:59 -0600 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2012-03-05 15:17:59 -0600 |
commit | dc9ecc600aa766caa3e7d718b0b8656da4ba1f70 (patch) | |
tree | 0ecf13a72974e8647aa13a9d022da52183cd1a3f | |
parent | b3e21e8ae240cb2a44a56b174b12d50740264fcc (diff) | |
download | fork-ledger-dc9ecc600aa766caa3e7d718b0b8656da4ba1f70.tar.gz fork-ledger-dc9ecc600aa766caa3e7d718b0b8656da4ba1f70.tar.bz2 fork-ledger-dc9ecc600aa766caa3e7d718b0b8656da4ba1f70.zip |
Guard against double-freeing of report objects
-rw-r--r-- | src/report.cc | 91 | ||||
-rw-r--r-- | src/report.h | 2 |
2 files changed, 59 insertions, 34 deletions
diff --git a/src/report.cc b/src/report.cc index 2d825751..7789ff80 100644 --- a/src/report.cc +++ b/src/report.cc @@ -1386,8 +1386,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind, switch (*p) { case 'a': if (is_eq(p, "accounts")) { - return WRAP_FUNCTOR(reporter<>(new report_accounts(*this), *this, - "#accounts")); + return WRAP_FUNCTOR(reporter<>(post_handler_ptr(new report_accounts(*this)), + *this, "#accounts")); } break; @@ -1395,9 +1395,10 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind, if (*(p + 1) == '\0' || is_eq(p, "bal") || is_eq(p, "balance")) { return expr_t::op_t::wrap_functor (reporter<account_t, acct_handler_ptr, &report_t::accounts_report> - (new format_accounts(*this, report_format(HANDLER(balance_format_)), - maybe_format(HANDLER(prepend_format_)), - HANDLER(prepend_width_).value.to_size_t()), + (acct_handler_ptr(new format_accounts + (*this, report_format(HANDLER(balance_format_)), + maybe_format(HANDLER(prepend_format_)), + HANDLER(prepend_width_).value.to_size_t())), *this, "#balance")); } else if (is_eq(p, "budget")) { @@ -1407,11 +1408,24 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind, if (! (budget_flags & ~BUDGET_WRAP_VALUES)) budget_flags |= BUDGET_BUDGETED; +#if 0 +#define POSTS_REPORT(formatter) + return WRAP_FUNCTOR(reporter<>(post_handler_ptr(formatter), *this, + string("#") + p)); + +#define ACCOUNTS_REPORT(formatter) + return WRAP_FUNCTOR(reporter<account_t, acct_handler_ptr, + &report_t::accounts_report> + (acct_handler_ptr(formatter), *this, + string("#") + p)); +#endif + return expr_t::op_t::wrap_functor (reporter<account_t, acct_handler_ptr, &report_t::accounts_report> - (new format_accounts(*this, report_format(HANDLER(budget_format_)), - maybe_format(HANDLER(prepend_format_)), - HANDLER(prepend_width_).value.to_size_t()), + (acct_handler_ptr(new format_accounts + (*this, report_format(HANDLER(budget_format_)), + maybe_format(HANDLER(prepend_format_)), + HANDLER(prepend_width_).value.to_size_t())), *this, "#budget")); } break; @@ -1420,9 +1434,10 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind, if (is_eq(p, "csv")) { return WRAP_FUNCTOR (reporter<> - (new format_posts(*this, report_format(HANDLER(csv_format_)), - maybe_format(HANDLER(prepend_format_)), - HANDLER(prepend_width_).value.to_size_t()), + (post_handler_ptr(new format_posts + (*this, report_format(HANDLER(csv_format_)), + maybe_format(HANDLER(prepend_format_)), + HANDLER(prepend_width_).value.to_size_t())), *this, "#csv")); } else if (is_eq(p, "cleared")) { @@ -1430,31 +1445,35 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind, "(amount, cleared ? amount : 0)"); return expr_t::op_t::wrap_functor (reporter<account_t, acct_handler_ptr, &report_t::accounts_report> - (new format_accounts(*this, report_format(HANDLER(cleared_format_)), - maybe_format(HANDLER(prepend_format_)), - HANDLER(prepend_width_).value.to_size_t()), + (acct_handler_ptr(new format_accounts + (*this, report_format(HANDLER(cleared_format_)), + maybe_format(HANDLER(prepend_format_)), + HANDLER(prepend_width_).value.to_size_t())), *this, "#cleared")); } else if (is_eq(p, "convert")) { return WRAP_FUNCTOR(convert_command); } else if (is_eq(p, "commodities")) { - return WRAP_FUNCTOR(reporter<>(new report_commodities(*this), *this, - "#commodities")); + return WRAP_FUNCTOR(reporter<> + (post_handler_ptr(new report_commodities(*this)), + *this, "#commodities")); } break; case 'e': if (is_eq(p, "equity")) { HANDLER(generated).on_only(string("#equity")); - return WRAP_FUNCTOR(reporter<>(new print_xacts(*this), *this, "#equity")); + return WRAP_FUNCTOR(reporter<>(post_handler_ptr(new print_xacts(*this)), + *this, "#equity")); } else if (is_eq(p, "entry")) { return WRAP_FUNCTOR(xact_command); } else if (is_eq(p, "emacs")) { return WRAP_FUNCTOR - (reporter<>(new format_emacs_posts(output_stream), *this, "#emacs")); + (reporter<>(post_handler_ptr(new format_emacs_posts(output_stream)), + *this, "#emacs")); } else if (is_eq(p, "echo")) { return MAKE_FUNCTOR(report_t::echo_command); @@ -1465,7 +1484,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind, if (is_eq(p, "org")) { return WRAP_FUNCTOR (reporter<> - (new posts_to_org_table(*this, maybe_format(HANDLER(prepend_format_))), + (post_handler_ptr(new posts_to_org_table + (*this, maybe_format(HANDLER(prepend_format_)))), *this, "#org")); } break; @@ -1473,30 +1493,33 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind, case 'p': if (*(p + 1) == '\0' || is_eq(p, "print")) { return WRAP_FUNCTOR - (reporter<>(new print_xacts(*this, HANDLED(raw)), *this, "#print")); + (reporter<>(post_handler_ptr(new print_xacts(*this, HANDLED(raw))), + *this, "#print")); } else if (is_eq(p, "prices")) { return expr_t::op_t::wrap_functor (reporter<post_t, post_handler_ptr, &report_t::commodities_report> - (new format_posts(*this, report_format(HANDLER(prices_format_)), - maybe_format(HANDLER(prepend_format_)), - HANDLER(prepend_width_).value.to_size_t()), + (post_handler_ptr(new format_posts + (*this, report_format(HANDLER(prices_format_)), + maybe_format(HANDLER(prepend_format_)), + HANDLER(prepend_width_).value.to_size_t())), *this, "#prices")); } else if (is_eq(p, "pricedb")) { return expr_t::op_t::wrap_functor (reporter<post_t, post_handler_ptr, &report_t::commodities_report> - (new format_posts(*this, report_format(HANDLER(pricedb_format_)), - maybe_format(HANDLER(prepend_format_)), - HANDLER(prepend_width_).value.to_size_t()), + (post_handler_ptr(new format_posts + (*this, report_format(HANDLER(pricedb_format_)), + maybe_format(HANDLER(prepend_format_)), + HANDLER(prepend_width_).value.to_size_t())), *this, "#pricedb")); } else if (is_eq(p, "pricemap")) { return MAKE_FUNCTOR(report_t::pricemap_command); } else if (is_eq(p, "payees")) { - return WRAP_FUNCTOR(reporter<>(new report_payees(*this), *this, - "#payees")); + return WRAP_FUNCTOR(reporter<>(post_handler_ptr(new report_payees(*this)), + *this, "#payees")); } break; @@ -1504,9 +1527,10 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind, if (*(p + 1) == '\0' || is_eq(p, "reg") || is_eq(p, "register")) { return WRAP_FUNCTOR (reporter<> - (new format_posts(*this, report_format(HANDLER(register_format_)), - maybe_format(HANDLER(prepend_format_)), - HANDLER(prepend_width_).value.to_size_t()), + (post_handler_ptr(new format_posts + (*this, report_format(HANDLER(register_format_)), + maybe_format(HANDLER(prepend_format_)), + HANDLER(prepend_width_).value.to_size_t())), *this, "#register")); } else if (is_eq(p, "reload")) { @@ -1525,7 +1549,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind, if (is_eq(p, "xact")) return WRAP_FUNCTOR(xact_command); else if (is_eq(p, "xml")) - return WRAP_FUNCTOR(reporter<>(new format_xml(*this), *this, "#xml")); + return WRAP_FUNCTOR(reporter<>(post_handler_ptr(new format_xml(*this)), + *this, "#xml")); break; } break; @@ -1550,7 +1575,7 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind, if (is_eq(p, "generate")) { return expr_t::op_t::wrap_functor (reporter<post_t, post_handler_ptr, &report_t::generate_report> - (new print_xacts(*this), *this, "#generate")); + (post_handler_ptr(new print_xacts(*this)), *this, "#generate")); } break; case 'p': diff --git a/src/report.h b/src/report.h index 35d45437..03eee78b 100644 --- a/src/report.h +++ b/src/report.h @@ -1019,7 +1019,7 @@ class reporter string whence; public: - reporter(item_handler<Type> * _handler, + reporter(shared_ptr<item_handler<Type> > _handler, report_t& _report, const string& _whence) : handler(_handler), report(_report), whence(_whence) {} |