2002-05-15 Benjamin Kosnik <bkoz@redhat.com>
authorbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 15 May 2002 13:15:17 +0000 (13:15 +0000)
committerbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 15 May 2002 13:15:17 +0000 (13:15 +0000)
PR libstdc++/6594
* src/strstream.cc (strstreambuf): Fix leak.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@53486 138bc75d-0d04-0410-961f-82ee72b054a4

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

index d6fc098..4018151 100644 (file)
@@ -1,3 +1,8 @@
+2002-05-15  Benjamin Kosnik  <bkoz@redhat.com>
+
+       PR libstdc++/6594
+       * src/strstream.cc (strstreambuf): Fix leak.
+
 2002-05-15  Paolo Carlini  <pcarlini@unitus.it>
 
        PR libstdc++/6648
index 2160c44..7bd8d9c 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);
   }
 }
 
@@ -139,7 +139,14 @@ strstreambuf::strstreambuf(const unsigned char* get, streamsize n)
 strstreambuf::~strstreambuf()
 {
   if (_M_dynamic && !_M_frozen)
-    _M_free(eback());
+    {
+      char* p = this->eback();
+      _M_free(p);
+      if (p == _M_buf)
+       _M_buf = 0;
+    }
+  if (_M_buf)
+    _M_free(_M_buf);
 }
 
 void strstreambuf::freeze(bool frozenflag)