--- libg++-2.7.1/libio/strstream.cc.orig Thu Jun 15 23:42:49 1995 +++ libg++-2.7.1/libio/strstream.cc Fri May 9 20:37:22 1997 @@ -141,11 +141,38 @@ void strstreambuf::init_static(char *ptr, int size, char *pstart) { + /* Patch (chunk 1/2) by Wolfgang Reimer + * Date: 5/7/97 + * fixes a memory allocation bug in the libio code. The bug will become + * effective when the allocation methods assigned to + * _allocate_buffer/_free_buffer are different from the allocation methods + * assigned to ALLOC_BUF/FREE_BUF in the C part of libio. This condition is + * true in the default case when using the linux-libc5.3.12+ which now uses + * mmap/munmap for buffer allocation handling (POSIX?). + * Calling the function assigned to _s._free_buffer at this point will make + * sure that the buffer memory will be freed with the right method. Otherwise + * the call to the below C function will free the buffer [exactly in + * _IO_setb()] with the method defined to ALLOC_BUF in the C part of libio. + */ + if (_IO_buf_base && !(_flags & _IO_USER_BUF)) + (_s._free_buffer)(_IO_buf_base); + _IO_buf_base = NULL; + /* End allocation bug fix (chunk 1/2) */ + _IO_str_init_static (this, ptr, size, pstart); } void strstreambuf::init_readonly (const char *ptr, int size) { + /* Patch (chunk 2/2) by Wolfgang Reimer + * Date: 5/7/97 + * fixes a memory allocation bug in the libio code (see explanation above). + */ + if (_IO_buf_base && !(_flags & _IO_USER_BUF)) + (_s._free_buffer)(_IO_buf_base); + _IO_buf_base = NULL; + /* End allocation bug fix (chunk 2/2) */ + _IO_str_init_readonly (this, ptr, size); }