Fixed another memory bug in by_payee_xacts

This commit is contained in:
John Wiegley 2009-02-21 04:12:10 -04:00
parent aeea1cb3e1
commit 6548da04cd
3 changed files with 21 additions and 20 deletions

View file

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

View file

@ -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() {

View file

@ -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)