This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] Small follow-ups to recent 28277 commit


Hi,

tested x86-linux, committed to mainline.

Paolo.

///////////////////
2006-10-14  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/ostream.tcc (operator<<(basic_ostream<>&,
	const char*)): Further fix for throwing widen.
2006-10-14  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/ostream.tcc (operator<<(basic_ostream<>&,
	const char*)): Fix thinko in change for libstdc++/28277,
	avoid memory leaks.
Index: include/bits/ostream.tcc
===================================================================
--- include/bits/ostream.tcc	(revision 117729)
+++ include/bits/ostream.tcc	(working copy)
@@ -325,17 +325,20 @@
 	  const size_t __clen = char_traits<char>::length(__s);      
 	  _CharT* __ws = 0;
 	  try
-	    { __ws = new _CharT[__clen]; }
+	    { 
+	      __ws = new _CharT[__clen];
+	      for (size_t  __i = 0; __i < __clen; ++__i)
+		__ws[__i] = __out.widen(__s[__i]);
+	    }
 	  catch(...)
 	    {
+	      delete [] __ws;
 	      __out._M_setstate(ios_base::badbit);
 	      return __out;
 	    }
 
 	  try
 	    {
-	      for (size_t  __i = 0; __i < __clen; ++__i)
-		__ws[__i] = __out.widen(__s[__i]);
 	      __out._M_insert(__ws, __clen);
 	      delete [] __ws;
 	    }
Index: include/bits/ostream.tcc
===================================================================
--- include/bits/ostream.tcc	(revision 117715)
+++ include/bits/ostream.tcc	(working copy)
@@ -320,19 +320,30 @@
 	__out.setstate(ios_base::badbit);
       else
 	{
+	  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+	  // 167.  Improper use of traits_type::length()
+	  const size_t __clen = char_traits<char>::length(__s);      
+	  _CharT* __ws = 0;
 	  try
+	    { __ws = new _CharT[__clen]; }
+	  catch(...)
 	    {
-	      // _GLIBCXX_RESOLVE_LIB_DEFECTS
-	      // 167.  Improper use of traits_type::length()
-	      const size_t __clen = char_traits<char>::length(__s);      
-	      _CharT* __ws = new _CharT[__clen];
+	      __out._M_setstate(ios_base::badbit);
+	      return __out;
+	    }
+
+	  try
+	    {
 	      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;
     }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]