Recent strstream regression: reversion needed?

B. Kosnik bkoz@nabi.net
Mon Jun 3 08:30:00 GMT 2002


> which I have confirmed, on x86-linux: the seg fault happens when 
> strtreambuf::~strstreambuf() is called.

bummer

> strstreambuf::~strstreambuf()
> {
>   if (_M_dynamic && !_M_frozen)
>     {
>       char* p = this->eback();
>       _M_free(p);
>       if (p == _M_buf)
>         _M_buf = 0;
>     }
>   if (_M_buf)
>     _M_free(_M_buf);
> }
> 
> During the execution of the testcase overflow() is called: the
> original buffer _M_buf is *disposed* and a new one allocated (sized 32
> = 2 x 16), pointed by eback(). Therefore, in general, even when p !=
> _M_buf it is *no* good to call _M_free(_M_buf), and in fact, it seems
> to me, completely unnecessary.

No. It's necessary. That memory is allocated, it needs to be cleaned up.

Try adding

	    _M_buf = buf;

in strstreambuf::overflow. 

I've a patch attached, but I have to run now. It's the above, with a
strstream reformat. You might check it out if you're interested. I'll
try to finish it up tomorrow. I think it'll do the job.

-benjamin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p.20020603
Type: application/octet-stream
Size: 28657 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20020603/d6a136b2/attachment.obj>


More information about the Libstdc++ mailing list