]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/stream.cpp
made wxTextFile work in Unicode; also made it possible to use it with non seekable...
[wxWidgets.git] / src / common / stream.cpp
index 435b60f266a6c6814cce08149b66d037e933a3b4..73dde47896f15a1c358f7d203881d98ec6d6ffe2 100644 (file)
@@ -117,7 +117,10 @@ wxStreamBuffer::wxStreamBuffer(const wxStreamBuffer& buffer)
 void wxStreamBuffer::FreeBuffer()
 {
     if ( m_destroybuf )
+    {
         free(m_buffer_start);
+        m_buffer_start = NULL;
+    }
 }
 
 wxStreamBuffer::~wxStreamBuffer()
@@ -163,15 +166,15 @@ void wxStreamBuffer::SetBufferIO(void *start,
 
 void wxStreamBuffer::SetBufferIO(size_t bufsize)
 {
-    // start by freeing the old buffer
-    FreeBuffer();
-
     if ( bufsize )
     {
+        // this will free the old buffer and allocate the new one
         SetBufferIO(malloc(bufsize), bufsize, true /* take ownership */);
     }
     else // no buffer size => no buffer
     {
+        // still free the old one
+        FreeBuffer();
         InitBuffer();
     }
 }