]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Fix a crash under rare circumstances at the end of a program.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 18 Sep 2012 02:21:32 +0000 (02:21 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 18 Sep 2012 02:21:32 +0000 (02:21 +0000)
git-svn-id: https://svn.dealii.org/trunk@26463 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.h
deal.II/source/base/logstream.cc
tests/base/log_crash_01.cc
tests/base/log_crash_01/cmp/generic

index aeb69157cb86d28511dea0d9b828491b9d027f6e..7ed9f6cc97b09b93a949f81c1d5fea69e522b636 100644 (file)
@@ -53,6 +53,14 @@ DoFHandler, in particular removal of specializations.
 <h3>Specific improvements</h3>
 
 <ol>
+<li> Fixed: If you pipe content into the deallog object and there
+is no end-line or flush after this content, and if a file stream
+is associated to this object, and if that happens at the end of
+the lifetime of the program, then the program would crash.
+This is now fixed.
+<br>
+(Timo Heister, Wolfgang Bangerth, 2012/09/17)
+
 <li> Fixed: The use of TableHandler::set_precision affected not only the
 precision with which elements of a table were printed, but also the
 precision carried by the output stream after writing the table was
index 98f06e51ddd89cdafdd86136224f4d8170ee5676..677e0c0f4cf7184824b31ce50e3c8f162dac2931 100644 (file)
@@ -81,7 +81,54 @@ LogStream::~LogStream()
         (*outstreams[id] != 0)
         &&
         (outstreams[id]->str().length() > 0))
-      *this << std::endl;
+      {
+                                        // except the situation is
+                                        // not quite that simple. if
+                                        // this object is the
+                                        // 'deallog' object, then it
+                                        // is destroyed upon exit of
+                                        // the program. since it's
+                                        // defined in a shared
+                                        // library that depends on
+                                        // libstdc++.so, destruction
+                                        // happens before destruction
+                                        // of std::cout/cerr, but
+                                        // after all file variables
+                                        // defined in user programs
+                                        // have been destroyed. in
+                                        // other words, if we get
+                                        // here and the object being
+                                        // destroyed is 'deallog' and
+                                        // if 'deallog' is associated
+                                        // with a file stream, then
+                                        // we're in trouble: we'll
+                                        // try to write to a file
+                                        // that doesn't exist any
+                                        // more, and we're likely
+                                        // going to crash (this is
+                                        // tested by
+                                        // base/log_crash_01). rather
+                                        // than letting it come to
+                                        // this, print a message to
+                                        // the screen (note that we
+                                        // can't issue an assertion
+                                        // here either since Assert
+                                        // may want to write to
+                                        // 'deallog' itself, and
+                                        // AssertThrow will throw an
+                                        // exception that can't be
+                                        // caught)
+       if ((this == &deallog) && file)
+         std::cerr << ("You still have content that was written to 'deallog' "
+                       "but not flushed to the screen or a file while the "
+                       "program is being terminated. This would lead to a "
+                       "segmentation fault. Make sure you flush the "
+                       "content of the 'deallog' object using 'std::endl' "
+                       "before the end of the program.")
+                   << std::endl;
+       else
+         *this << std::endl;
+      }
   }
 
   if (old_cerr)
index 4d2fd1c18ce4b9b1754f3999bd72b79122699707..ddeb38d72b67e68266f1001bf87f2e1c40828b59 100644 (file)
@@ -1,8 +1,8 @@
 //----------------------------  logtest.cc  ---------------------------
 //    $Id: logtest.cc 23710 2011-05-17 04:50:10Z bangerth $
-//    Version: $Name$ 
+//    Version: $Name$
 //
-//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007 by the deal.II authors
+//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2012 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
 
 int main()
 {
+  deal_II_exceptions::disable_abort_on_exception ();
+
   std::ofstream logfile("log_crash_01/output");
   deallog.attach(logfile);
+  deallog << "OK" << std::endl;
+
   deallog << "no newline here!";
 }
index 035550ac63ecb911675bf2bec0e4e14efdc25c9e..0fd8fc12f0b442283edd8868867114c242b04d11 100644 (file)
@@ -1,7 +1,2 @@
 
-DEAL::Test
-DEAL:l1::Test1
-DEAL:l1:l2::Test2Test3
-DEAL:l1:l2::Test4Test5
-DEAL:l1::Test6
-DEAL::Test7
+DEAL::OK

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.