summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-02-21 04:12:10 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-02-21 04:12:10 -0400
commit6548da04cdde83998ec380a1b47117b45b0d65f8 (patch)
tree7f022ce0139cce4a98f69dd96da4ef70272e5c7d
parentaeea1cb3e1c5c158294e1f08543065c2e602c94e (diff)
downloadfork-ledger-6548da04cdde83998ec380a1b47117b45b0d65f8.tar.gz
fork-ledger-6548da04cdde83998ec380a1b47117b45b0d65f8.tar.bz2
fork-ledger-6548da04cdde83998ec380a1b47117b45b0d65f8.zip
Fixed another memory bug in by_payee_xacts
-rw-r--r--src/filters.cc13
-rw-r--r--src/filters.h10
-rw-r--r--src/utils.cc18
3 files changed, 21 insertions, 20 deletions
diff --git a/src/filters.cc b/src/filters.cc
index f3b74aa3..13b62d9d 100644
--- a/src/filters.cc
+++ b/src/filters.cc
@@ -596,14 +596,6 @@ void xacts_as_equity::report_subtotal()
}
}
-by_payee_xacts::~by_payee_xacts()
-{
- TRACE_DTOR(by_payee_xacts);
-
- foreach (payee_subtotals_map::value_type& pair, payee_subtotals)
- checked_delete(pair.second);
-}
-
void by_payee_xacts::flush()
{
foreach (payee_subtotals_map::value_type& pair, payee_subtotals)
@@ -618,8 +610,9 @@ void by_payee_xacts::operator()(xact_t& xact)
{
payee_subtotals_map::iterator i = payee_subtotals.find(xact.entry->payee);
if (i == payee_subtotals.end()) {
- payee_subtotals_pair temp(xact.entry->payee,
- new subtotal_xacts(handler, amount_expr));
+ payee_subtotals_pair
+ temp(xact.entry->payee,
+ shared_ptr<subtotal_xacts>(new subtotal_xacts(handler, amount_expr)));
std::pair<payee_subtotals_map::iterator, bool> result
= payee_subtotals.insert(temp);
diff --git a/src/filters.h b/src/filters.h
index ea6874f6..112ebbcd 100644
--- a/src/filters.h
+++ b/src/filters.h
@@ -651,8 +651,8 @@ public:
*/
class by_payee_xacts : public item_handler<xact_t>
{
- typedef std::map<string, subtotal_xacts *> payee_subtotals_map;
- typedef std::pair<string, subtotal_xacts *> payee_subtotals_pair;
+ typedef std::map<string, shared_ptr<subtotal_xacts> > payee_subtotals_map;
+ typedef std::pair<string, shared_ptr<subtotal_xacts> > payee_subtotals_pair;
expr_t& amount_expr;
payee_subtotals_map payee_subtotals;
@@ -664,7 +664,9 @@ class by_payee_xacts : public item_handler<xact_t>
: item_handler<xact_t>(handler), amount_expr(_amount_expr) {
TRACE_CTOR(by_payee_xacts, "xact_handler_ptr, expr_t&");
}
- virtual ~by_payee_xacts();
+ virtual ~by_payee_xacts() {
+ TRACE_DTOR(by_payee_xacts);
+ }
virtual void flush();
virtual void operator()(xact_t& xact);
@@ -755,7 +757,7 @@ protected:
public:
generate_xacts(xact_handler_ptr handler)
: item_handler<xact_t>(handler) {
- TRACE_CTOR(dow_xacts, "xact_handler_ptr");
+ TRACE_CTOR(generate_xacts, "xact_handler_ptr");
}
virtual ~generate_xacts() {
diff --git a/src/utils.cc b/src/utils.cc
index d42ed79c..5f42eae5 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -292,21 +292,22 @@ void trace_ctor_func(void * ptr, const char * cls_name, const char * args,
void trace_dtor_func(void * ptr, const char * cls_name, std::size_t cls_size)
{
- memory_tracing_active = false;
-
if (! live_objects) return;
+ memory_tracing_active = false;
+
DEBUG("memory.debug", "TRACE_DTOR " << ptr << " " << cls_name);
live_objects_map::iterator i = live_objects->find(ptr);
if (i == live_objects->end()) {
std::cerr << "Attempting to delete " << ptr << " a non-living " << cls_name
<< std::endl;
- assert(false);
+ memory_tracing_active = true;
+ return;
}
- int ptr_count = live_objects->count(ptr);
- for (int x = 0; x < ptr_count; x++, i++) {
+ std::size_t ptr_count = live_objects->count(ptr);
+ for (std::size_t x = 0; x < ptr_count; x++, i++) {
if ((*i).second.first == cls_name) {
live_objects->erase(i);
break;
@@ -314,7 +315,12 @@ void trace_dtor_func(void * ptr, const char * cls_name, std::size_t cls_size)
}
object_count_map::iterator k = live_object_count->find(cls_name);
- VERIFY(k != live_object_count->end());
+ if (k == live_object_count->end()) {
+ std::cerr << "Failed to find " << cls_name << " in live object counts"
+ << std::endl;
+ memory_tracing_active = true;
+ return;
+ }
(*k).second.second -= cls_size;
if (--(*k).second.first == 0)