From 78a438f161f869b2ac34c9904b0a2a0cad12127c Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Sat, 14 Oct 2006 09:51:32 +0000 Subject: [PATCH] ostream.tcc (operator<<(basic_ostream<>&, const char*)): Fix thinko in change for libstdc++/28277, avoid memory leaks. 2006-10-14 Paolo Carlini * include/bits/ostream.tcc (operator<<(basic_ostream<>&, const char*)): Fix thinko in change for libstdc++/28277, avoid memory leaks. From-SVN: r117729 --- libstdc++-v3/ChangeLog | 6 ++++++ libstdc++-v3/include/bits/ostream.tcc | 21 ++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 9df16614528..f286f680be4 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2006-10-14 Paolo Carlini + + * include/bits/ostream.tcc (operator<<(basic_ostream<>&, + const char*)): Fix thinko in change for libstdc++/28277, + avoid memory leaks. + 2006-10-13 Paolo Carlini * include/bits/istream.tcc (operator>>(__istream_type& diff --git a/libstdc++-v3/include/bits/ostream.tcc b/libstdc++-v3/include/bits/ostream.tcc index 5bfde44dd3a..125e0fe4cb8 100644 --- a/libstdc++-v3/include/bits/ostream.tcc +++ b/libstdc++-v3/include/bits/ostream.tcc @@ -320,19 +320,30 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __out.setstate(ios_base::badbit); else { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 167. Improper use of traits_type::length() + const size_t __clen = char_traits::length(__s); + _CharT* __ws = 0; + try + { __ws = new _CharT[__clen]; } + catch(...) + { + __out._M_setstate(ios_base::badbit); + return __out; + } + try { - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 167. Improper use of traits_type::length() - const size_t __clen = char_traits::length(__s); - _CharT* __ws = new _CharT[__clen]; for (size_t __i = 0; __i < __clen; ++__i) __ws[__i] = __out.widen(__s[__i]); __out._M_insert(__ws, __clen); delete [] __ws; } catch(...) - { __out._M_setstate(ios_base::badbit); } + { + delete [] __ws; + __throw_exception_again; + } } return __out; } -- 2.30.2