summaryrefslogtreecommitdiff
path: root/format.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2004-08-19 03:28:48 -0400
committerJohn Wiegley <johnw@newartisans.com>2004-08-19 03:28:48 -0400
commitbf923ab33e9951d25611cb7193d6852e9113d929 (patch)
tree0c1f3b6367b42569ecfb297a5e3968fab742ac15 /format.cc
parent965e1fc28f725e830a6f51a5d41e7a3850d15b12 (diff)
downloadfork-ledger-bf923ab33e9951d25611cb7193d6852e9113d929.tar.gz
fork-ledger-bf923ab33e9951d25611cb7193d6852e9113d929.tar.bz2
fork-ledger-bf923ab33e9951d25611cb7193d6852e9113d929.zip
use std::auto_ptr wherever a thrown exception might otherwise leak memory
Diffstat (limited to 'format.cc')
-rw-r--r--format.cc15
1 files changed, 9 insertions, 6 deletions
diff --git a/format.cc b/format.cc
index 7b17a4cd..956dae62 100644
--- a/format.cc
+++ b/format.cc
@@ -45,7 +45,8 @@ std::auto_ptr<value_expr_t> format_t::total_expr;
element_t * format_t::parse_elements(const std::string& fmt)
{
- element_t * result = NULL;
+ std::auto_ptr<element_t> result;
+
element_t * current = NULL;
static char buf[1024];
@@ -57,8 +58,9 @@ element_t * format_t::parse_elements(const std::string& fmt)
continue;
}
- if (! result) {
- current = result = new element_t;
+ if (! result.get()) {
+ result.reset(new element_t);
+ current = result.get();
} else {
current->next = new element_t;
current = current->next;
@@ -148,8 +150,9 @@ element_t * format_t::parse_elements(const std::string& fmt)
}
if (q != buf) {
- if (! result) {
- current = result = new element_t;
+ if (! result.get()) {
+ result.reset(new element_t);
+ current = result.get();
} else {
current->next = new element_t;
current = current->next;
@@ -158,7 +161,7 @@ element_t * format_t::parse_elements(const std::string& fmt)
current->chars = std::string(buf, q);
}
- return result;
+ return result.release();
}
void format_t::format_elements(std::ostream& out,