Browse Source

HPCC-13578 Prevent logging from destroyed crit secs from segfaulting

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday 10 years ago
parent
commit
ced61e1423
3 changed files with 22 additions and 6 deletions
  1. 11 5
      system/jlib/jexcept.cpp
  2. 10 0
      system/jlib/jlog.cpp
  3. 1 1
      system/jlib/jmutex.hpp

+ 11 - 5
system/jlib/jexcept.cpp

@@ -511,7 +511,6 @@ void throwUnexpectedException(const char * where, const char * file, unsigned li
 
 void raiseAssertException(const char *assertion, const char *file, unsigned line)
 {
-    printStackReport();
     StringBuffer s;
     s.append("assert(");
     s.append(assertion);
@@ -519,12 +518,17 @@ void raiseAssertException(const char *assertion, const char *file, unsigned line
     s.append(file);
     s.append(", line ");
     s.append(line);
-    ERRLOG("%s",s.str());       // make sure doesn't get lost!
-    queryLogMsgManager()->flushQueue(10*1000);
+
+    if (queryLogMsgManager())
+    {
+        printStackReport();
+        ERRLOG("%s",s.str());       // make sure doesn't get lost!
+        queryLogMsgManager()->flushQueue(10*1000);
 #ifdef _DEBUG
-    // cause a breakpoint in the debugger if we are debugging.
-    //userBreakpoint();
+        // cause a breakpoint in the debugger if we are debugging.
+        //userBreakpoint();
 #endif
+    }
     
 #if 0
 #ifndef USING_MPATROL
@@ -1342,6 +1346,8 @@ void jlib_decl serializeException(IException * e, MemoryBuffer & out)
 
 void printStackReport()
 {
+    if (!queryLogMsgManager())
+        return;
 #ifdef _WIN32
     unsigned onstack=1234;
     doPrintStackReport(0, 0,(unsigned)&onstack);

+ 10 - 0
system/jlib/jlog.cpp

@@ -2237,13 +2237,23 @@ MODULE_EXIT()
 {
     delete thePrepender;
     for(unsigned compo = 0; compo<MSGCOMP_NUMBER; compo++)
+    {
         delete theReporters[compo];
+        theReporters[compo] = NULL;
+    }
     delete theManager;
     delete theSysLogEventLogger;
     delete theStderrHandler;
     delete thePassNoneFilter;
     delete thePassLocalFilter;
     delete thePassAllFilter;
+    thePrepender = NULL;
+    theManager = NULL;
+    theSysLogEventLogger = NULL;
+    theStderrHandler = NULL;
+    thePassNoneFilter = NULL;
+    thePassLocalFilter = NULL;
+    thePassAllFilter = NULL;
 }
 
 ILogMsgManager * queryLogMsgManager()

+ 1 - 1
system/jlib/jmutex.hpp

@@ -288,7 +288,7 @@ public:
     inline ~CriticalSection()
     {
 #ifdef _ASSERT_LOCK_SUPPORT
-        assertex(owner==0 && depth==0);
+        assert(owner==0 && depth==0);
 #endif
         pthread_mutex_destroy(&mutex);
     }