From 9db08c4c7de7b2058363bec4a3000f48fc78d580 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 28 Feb 2006 13:06:38 +0000 Subject: (read_binary_journal): Fixed a tiny memory leak when reading from a binary cache. --- binary.cc | 1 + format.h | 12 ++++++------ journal.cc | 2 +- journal.h | 3 +-- valexpr.cc | 11 +++++++---- valexpr.h | 17 +++++++++++++---- 6 files changed, 29 insertions(+), 17 deletions(-) diff --git a/binary.cc b/binary.cc index 958c0a79..513ee839 100644 --- a/binary.cc +++ b/binary.cc @@ -557,6 +557,7 @@ unsigned int read_binary_journal(std::istream& in, account_t::ident_t a_count = read_binary_long(data); accounts = accounts_next = new account_t *[a_count]; + delete journal->master; journal->master = read_binary_account(data, journal, master); if (read_binary_number(data)) journal->basket = accounts[read_binary_long(data) - 1]; diff --git a/format.h b/format.h index 3e644bd6..a2c5c89b 100644 --- a/format.h +++ b/format.h @@ -45,13 +45,13 @@ struct element_t DEPTH_SPACER }; - bool align_left; - unsigned int min_width; - unsigned int max_width; + bool align_left; + unsigned int min_width; + unsigned int max_width; - kind_t type; - std::string chars; - value_expr * val_expr; + kind_t type; + std::string chars; + value_expr * val_expr; struct element_t * next; diff --git a/journal.cc b/journal.cc index ceedb2c4..5b9765e1 100644 --- a/journal.cc +++ b/journal.cc @@ -309,7 +309,7 @@ void auto_entry_t::extend_entry(entry_base_t& entry) account_t::~account_t() { - DEBUG_PRINT("ledger.memory.dtors", "dtor account_t"); + DEBUG_PRINT("ledger.memory.dtors", "dtor account_t " << this); //assert(! data); for (accounts_map::iterator i = accounts.begin(); diff --git a/journal.h b/journal.h index 6eb28b90..65e6d609 100644 --- a/journal.h +++ b/journal.h @@ -283,9 +283,8 @@ class account_t const std::string& _note = "") : parent(_parent), name(_name), note(_note), depth(parent ? parent->depth + 1 : 0), data(NULL), ident(0) { - DEBUG_PRINT("ledger.memory.ctors", "ctor account_t"); + DEBUG_PRINT("ledger.memory.ctors", "ctor account_t " << this); } - ~account_t(); bool operator==(const account_t& account) { diff --git a/valexpr.cc b/valexpr.cc index 41dd9b25..8222da40 100644 --- a/valexpr.cc +++ b/valexpr.cc @@ -44,7 +44,7 @@ bool compute_amount(value_expr_t * expr, amount_t& amt, value_expr_t::~value_expr_t() { - DEBUG_PRINT("ledger.memory.dtors", "dtor value_expr_t"); + DEBUG_PRINT("ledger.memory.dtors", "dtor value_expr_t " << this); DEBUG_PRINT("ledger.valexpr.memory", "Destroying " << this); assert(refc == 0); @@ -1279,7 +1279,8 @@ void init_value_expr() globals->define("P", node); globals->define("val", node); globals->define("value", node); - parse_boolean_expr("current_value(x)=P(x,m)", globals); + node = parse_boolean_expr("current_value(x)=P(x,m)", globals); + delete node; // Macros node = parse_value_expr("P(a,d)"); @@ -1298,8 +1299,10 @@ void init_value_expr() globals->define("G", node); globals->define("gain_total", node); - parse_boolean_expr("min(x,y)=xy?x:y", globals); + node = parse_boolean_expr("min(x,y)=xy?x:y", globals); + delete node; } value_expr_t * parse_value_expr(std::istream& in, scope_t * scope, diff --git a/valexpr.h b/valexpr.h index a9a02854..b91dd460 100644 --- a/valexpr.h +++ b/valexpr.h @@ -151,7 +151,10 @@ struct value_expr_t value_expr_t(const kind_t _kind) : kind(_kind), refc(0), left(NULL), right(NULL) { - DEBUG_PRINT("ledger.memory.ctors", "ctor value_expr_t"); + DEBUG_PRINT("ledger.memory.ctors", "ctor value_expr_t " << this); + } + value_expr_t(const value_expr_t&) { + DEBUG_PRINT("ledger.memory.ctors", "ctor value_expr_t (copy) " << this); } ~value_expr_t(); @@ -203,8 +206,11 @@ struct scope_t symbol_map symbols; - scope_t(scope_t * _parent = NULL) : parent(_parent) {} + scope_t(scope_t * _parent = NULL) : parent(_parent) { + DEBUG_PRINT("ledger.memory.ctors", "ctor scope_t"); + } ~scope_t() { + DEBUG_PRINT("ledger.memory.dtors", "dtor scope_t"); for (symbol_map::iterator i = symbols.begin(); i != symbols.end(); i++) @@ -328,6 +334,7 @@ class value_expr : public value_calc public: value_expr(const std::string& _expr) : expr(_expr) { + DEBUG_PRINT("ledger.memory.ctors", "ctor value_expr"); try { parsed = parse_value_expr(expr); parsed->acquire(); @@ -337,9 +344,11 @@ public: expr + "': " + err.what()); } } - value_expr(value_expr_t * _parsed) : parsed(_parsed->acquire()) {} - + value_expr(value_expr_t * _parsed) : parsed(_parsed->acquire()) { + DEBUG_PRINT("ledger.memory.ctors", "ctor value_expr"); + } virtual ~value_expr() { + DEBUG_PRINT("ledger.memory.dtors", "dtor value_expr"); if (parsed != NULL) parsed->release(); } -- cgit v1.2.3