From 632a7974d829a4d503a2f4f7f78eafe21158959d Mon Sep 17 00:00:00 2001 From: harris_s Date: Thu, 4 Nov 2004 23:11:00 +0000 Subject: Thu Nov 4 17:06:08 CST 2004 Scott Harris --- ChangeLog | 22 ++++++++++++++++++++++ tests/Log_Msg_Test.cpp | 3 ++- tests/Test_Output.cpp | 24 +++++++++++++++++++----- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 993966a5e15..2127a8e8534 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +Thu Nov 4 17:06:08 CST 2004 Scott Harris + + * test/Test_Output.cpp: + + Fix a bug introduced by a memory leak fix in Logging_Strategy.cpp, + Mon Oct 18 21:13:02 2004 Douglas C. Schmidt + , that broke the test/Logging_Strategy_Test on some platforms. + The problem is that Test_Output gives its file stream away + to ACE_LOG_MSG and then ACE_Logging_Strategry::init destroys the + stream but ACE_END_TEST still tries to close and destory it. + The solution was to only have Test_Output close/destroy the + stream if it has not already be changed in ACE_LOG_MSG. + + * test/Log_Msg_Test.cpp: + + The above change made it so ACE_Test_Output::output_file () + returns the ACE_MSG_LOG stream so it would not return + a possibly destroyed stream. Log_Msg_Test had + to be changed to save off the message stream when it + switched to a different file stream and then back + to the original. + Thu Nov 4 14:00:50 2004 J.T. Conklin * ace/QoS/Makefile.am: diff --git a/tests/Log_Msg_Test.cpp b/tests/Log_Msg_Test.cpp index daff113d3b4..293e0354589 100644 --- a/tests/Log_Msg_Test.cpp +++ b/tests/Log_Msg_Test.cpp @@ -353,6 +353,7 @@ test_ostream (void) if (myostream.bad ()) return -1; + OFSTREAM *old_stream = ace_file_stream::instance ()->output_file (); // Set the ostream. ACE_LOG_MSG->msg_ostream (&myostream); @@ -360,7 +361,7 @@ test_ostream (void) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("fourth message\n"))); // Set the ostream back to the test's log file. - ACE_LOG_MSG->msg_ostream (ace_file_stream::instance ()->output_file ()); + ACE_LOG_MSG->msg_ostream (old_stream); // Now close the ostream file and check its contents. myostream.close (); diff --git a/tests/Test_Output.cpp b/tests/Test_Output.cpp index adb9e9e8e46..ed0e180faa8 100644 --- a/tests/Test_Output.cpp +++ b/tests/Test_Output.cpp @@ -48,6 +48,8 @@ ACE_Test_Output::ACE_Test_Output (void) ACE_Test_Output::~ACE_Test_Output (void) { #if !defined (ACE_LACKS_IOSTREAM_TOTALLY) && !defined (ACE_PSOS) + ACE_OSTREAM_TYPE *log_msg_stream = ACE_LOG_MSG->msg_ostream (); + ACE_LOG_MSG->msg_ostream (&cerr); #endif /* ! ACE_LACKS_IOSTREAM_TOTALLY && ! ACE_PSOS */ @@ -55,14 +57,21 @@ ACE_Test_Output::~ACE_Test_Output (void) ACE_LOG_MSG->set_flags (ACE_Log_Msg::STDERR); #if !defined (ACE_LACKS_IOSTREAM_TOTALLY) && !defined (ACE_HAS_PHARLAP) - delete this->output_file_; + if (this->output_file_ == log_msg_stream) + delete this->output_file_; + // else something else changed the stream and hence should + // have closed and deleted the output_file_ #endif /* ! ACE_LACKS_IOSTREAM_TOTALLY */ } OFSTREAM * ACE_Test_Output::output_file (void) { - return this->output_file_; + // the output_file_ is given to ACE_LOG_MSG + // and something else might destroy and/or change the stream + // so return what ACE_LOG_MSG is using. + return dynamic_cast( ACE_LOG_MSG->msg_ostream () ); + //return this->output_file_; } int @@ -146,7 +155,7 @@ ACE_Test_Output::set_output (const ACE_TCHAR *filename, int append) this->output_file_ = ACE_OS::fopen (temp, fmode); # endif /* ACE_LACKS_IOSTREAM_TOTALLY */ - ACE_LOG_MSG->msg_ostream (this->output_file ()); + ACE_LOG_MSG->msg_ostream (this->output_file_); #endif /* ACE_HAS_PHARLAP */ ACE_LOG_MSG->clr_flags (ACE_Log_Msg::STDERR | ACE_Log_Msg::LOGGER ); @@ -159,8 +168,13 @@ void ACE_Test_Output::close (void) { #if !defined (ACE_LACKS_IOSTREAM_TOTALLY) - this->output_file_->flush (); - this->output_file_->close (); + if (this->output_file_ == ACE_LOG_MSG->msg_ostream () ) + { + this->output_file_->flush (); + this->output_file_->close (); + } + // else something else changed the stream and hence should + // have closed and deleted the output_file_ #else ACE_OS::fflush (this->output_file_); ACE_OS::fclose (this->output_file_); -- cgit v1.2.1