libstdc++/3045: global stream objects destructor semantics

theonetruekenny@yahoo.com theonetruekenny@yahoo.com
Mon Jun 4 01:26:00 GMT 2001


>Number:         3045
>Category:       libstdc++
>Synopsis:       global stream objects destructor semantics
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jun 04 01:26:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     theonetruekenny@yahoo.com
>Release:        cvs 20010603
>Organization:
>Environment:
source
>Description:
In libstdc++-v3/src/ios.cc, function ios_base::Init::_S_ios_destroy are these lines:
	delete cout.rdbuf();
	delete cin.rdbuf();
	delete cerr.rdbuf();

These are no doubt the counterpart to the following lines from ios_base::Init::_S_ios_create:
	new (&cout) ostream(new filebuf(stdout, ios_base::out, __bufsize));
	new (&cin) istream(new filebuf(stdin, ios_base::in, 1));
	new (&cerr) ostream(new filebuf(stderr, ios_base::out, __bufsize));

However, the use of the rdbuf() method is incorrect. (See previous bug report dealing with rdbuf()).  This use of rdbuf() could lead to badness if cout/cin/cerr/clog were to be redirected.
>How-To-Repeat:
#include <fstream>
#include <iostream>

std::basic_filebuf b1;

int main()
{
  b1.open("foo");
  cout.rdbuf( b1 );
  std::cout << "hello" << std::endl;
  return 0;
}
// at program termination, b1 is deleted by 
// ios_base::Init::_S_ios_destroy,
// and the streambuf created to handle output
// to stdout is leaked.
>Fix:
create three global filebuf's in globals.cc.
add constructors in ios.cc to in-place construct and destroy these filebufs.
modify the constructors for cout/cin/cerr/clog in ios.cc to use these filebufs.
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list