From bf923ab33e9951d25611cb7193d6852e9113d929 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 19 Aug 2004 03:28:48 -0400 Subject: use std::auto_ptr wherever a thrown exception might otherwise leak memory --- format.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'format.cc') 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 format_t::total_expr; element_t * format_t::parse_elements(const std::string& fmt) { - element_t * result = NULL; + std::auto_ptr 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, -- cgit v1.2.3