From mboxrd@z Thu Jan 1 00:00:00 1970 From: theonetruekenny@yahoo.com To: gcc-gnats@gcc.gnu.org Cc: kenny.simpson@gs.com Subject: libstdc++/3045: global stream objects destructor semantics Date: Mon, 04 Jun 2001 01:26:00 -0000 Message-id: <20010604082334.25473.qmail@sourceware.cygnus.com> X-SW-Source: 2001-06/msg00062.html List-Id: >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 #include 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: