]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libstdc++/6594 (strstreambuf leaks 16 bytes - gcc 3.0.x)
authorBenjamin Kosnik <bkoz@redhat.com>
Sat, 18 May 2002 14:44:52 +0000 (14:44 +0000)
committerBenjamin Kosnik <bkoz@gcc.gnu.org>
Sat, 18 May 2002 14:44:52 +0000 (14:44 +0000)
2002-05-18  Benjamin Kosnik  <bkoz@redhat.com>

PR libstdc++/6594
* src/strstream.cc (strstreambuf): Fix leak.

From-SVN: r53585

libstdc++-v3/ChangeLog
libstdc++-v3/src/strstream.cc

index 511febee833a2a441300c7266fc5d1a2fade437f..bcc9e236af21116a27fff9a61bcda01f42578bf7 100644 (file)
@@ -1,3 +1,8 @@
+2002-05-18  Benjamin Kosnik  <bkoz@redhat.com>
+
+       PR libstdc++/6594
+       * src/strstream.cc (strstreambuf): Fix leak.
+
 2002-05-18  Benjamin Kosnik  <bkoz@redhat.com>
 
        * testsuite/22_locale/ctype_scan_char.cc: Tweak.
index 2160c440be2757c8d176d8858824877834364588..1af46bb5654dd109ebfed65d09c4db2ecc6d8f79 100644 (file)
@@ -64,13 +64,13 @@ strstreambuf::strstreambuf(streamsize initial_capacity)
     _M_alloc_fun(0), _M_free_fun(0),
     _M_dynamic(true), _M_frozen(false), _M_constant(false)
 {
-  streamsize n = max(initial_capacity, streamsize(16));
-
-  char* buf = _M_alloc(n);
-  if (buf) {
-    setp(buf, buf + n);
-    setg(buf, buf, buf);
-  }
+  _M_buf_size = _M_buf_size_opt = max(initial_capacity, streamsize(16));
+  _M_buf = _M_alloc(_M_buf_size);
+  if (_M_buf) 
+    {
+      setp(_M_buf, _M_buf + _M_buf_size);
+      setg(_M_buf, _M_buf, _M_buf);
+    }
 }
 
 strstreambuf::strstreambuf(void* (*alloc_f)(size_t), void (*free_f)(void*))
@@ -78,12 +78,12 @@ strstreambuf::strstreambuf(void* (*alloc_f)(size_t), void (*free_f)(void*))
     _M_alloc_fun(alloc_f), _M_free_fun(free_f),
     _M_dynamic(true), _M_frozen(false), _M_constant(false)
 {
-  streamsize n = 16;
-
-  char* buf = _M_alloc(n);
-  if (buf) {
-    setp(buf, buf + n);
-    setg(buf, buf, buf);
+  _M_buf_size = _M_buf_size_opt = 16;
+  _M_buf = _M_alloc(_M_buf_size);
+  if (_M_buf) 
+    {
+      setp(_M_buf, _M_buf + _M_buf_size);
+      setg(_M_buf, _M_buf, _M_buf);
   }
 }
 
@@ -140,6 +140,8 @@ strstreambuf::~strstreambuf()
 {
   if (_M_dynamic && !_M_frozen)
     _M_free(eback());
+  if (_M_buf)
+    _M_free(_M_buf);
 }
 
 void strstreambuf::freeze(bool frozenflag)