]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Debug vsr/26457
authorvsr <vsr@opencascade.com>
Fri, 29 Oct 2021 13:03:59 +0000 (16:03 +0300)
committervsr <vsr@opencascade.com>
Wed, 24 Nov 2021 14:14:46 +0000 (17:14 +0300)
src/SALOMETraceCollector/SALOMETraceCollector.cxx
src/SALOMETraceCollector/SALOMETraceCollector.hxx
src/SALOMETraceCollector/Test/SALOMETraceCollectorTest.cxx
src/SALOMETraceCollector/Test/TestSALOMETraceCollector.cxx
src/SALOMETraceCollector/Test/TestSALOMETraceCollector.py
src/SALOMETraceCollector/TraceCollector_WaitForServerReadiness.cxx
src/SALOMETraceCollector/TraceCollector_WaitForServerReadiness.hxx
src/Utils/OpUtil.cxx
src/Utils/Utils_ORB_INIT.cxx

index 8d69598dc88f9124d84b52e0b55d1db5defe1262..716cd598590a166bb9996a4f243dc474a558ff8d 100644 (file)
 #include <cstdlib>
 #include <omniORB4/CORBA.h>
 
-#include "OpUtil.hxx"
 #include "Utils_SALOME_Exception.hxx"
 #include "SALOMETraceCollector.hxx"
 #include "TraceCollector_WaitForServerReadiness.hxx"
 #include <SALOMEconfig.h>
 #include CORBA_CLIENT_HEADER(Logger)
 
-// Class attributes initialisation, for class method SALOMETraceCollector::run
-
-CORBA::ORB_ptr SALOMETraceCollector::_orb = 0;
-
 // ============================================================================
 /*!
  *  This class is for use with CORBA, inside SALOME.
@@ -62,7 +57,6 @@ BaseTraceCollector* SALOMETraceCollector::instance()
       if (_singleton == 0)                     // another thread may have got
         {                                      // the lock after the first test
           BaseTraceCollector* myInstance = new SALOMETraceCollector();
-          _orb = KERNEL::GetRefToORB();
 
           sem_init(&_sem,0,0); // to wait until run thread is initialized
           pthread_t traceThread;
@@ -100,7 +94,7 @@ void* SALOMETraceCollector::run(void* /*bid*/)
   SALOME_Logger::Logger_var m_pInterfaceLogger;
   CORBA::Object_var obj;
 
-  obj = TraceCollector_WaitForServerReadiness(_orb,"Logger");
+  obj = TraceCollector_WaitForServerReadiness("Logger");
   if (!CORBA::is_nil(obj))
     m_pInterfaceLogger = SALOME_Logger::Logger::_narrow(obj);
   if (CORBA::is_nil(m_pInterfaceLogger))
@@ -129,7 +123,8 @@ void* SALOMETraceCollector::run(void* /*bid*/)
         }
 
       myTraceBuffer->retrieve(myTrace);
-      if (!CORBA::is_nil(_orb))
+      //if (!CORBA::is_nil(_orb))
+      if (true)
         {
           if (myTrace.traceType == ABORT_MESS)
             {
index e557dc0ebd825653f8f6b5bf01141d4815fa572f..6bb8e73e4f26faef1751033895f388fe785899fa 100644 (file)
@@ -29,7 +29,6 @@
 #define _SALOMETRACECOLLECTOR_HXX_
 
 #include <string>
-#include <omniORB4/CORBA.h>
 #include "BaseTraceCollector.hxx"
 #include "LocalTraceBufferPool.hxx"
 
@@ -56,9 +55,6 @@ class SALOMETRACECOLLECTOR_EXPORT SALOMETraceCollector:
 
  protected:
   SALOMETraceCollector();
-
- private:
-  static CORBA::ORB_ptr _orb;
 };
 
 #endif
index 317bd27b085357883fa7696f20e66eb1a54c45cc..15abff957e92b12789a09ec01502bdf01b1edc2a 100644 (file)
@@ -69,6 +69,7 @@ void *PrintHello(void *threadid);
 void 
 SALOMETraceCollectorTest::testLoadBufferPoolCORBA()
 {
+  LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
   std::string s = "with_logger";
   CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite
 
@@ -92,7 +93,6 @@ SALOMETraceCollectorTest::testLoadBufferPoolCORBA()
     }
   MESSAGE(" ---- end of PrintHello threads ---- ");
 
-  LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
   CPPUNIT_ASSERT(bp1);
   bp1->deleteInstance(bp1);
 }
index 5461210c241f9733655aa0ce405a31718a557e9e..a40e7735890e281156e7e1b2edc6b490d1e9457e 100644 (file)
@@ -27,7 +27,7 @@
 
 // --- Registers the fixture into the 'registry'
 
-CPPUNIT_TEST_SUITE_REGISTRATION( SALOMELocalTraceTest );
+//CPPUNIT_TEST_SUITE_REGISTRATION( SALOMELocalTraceTest );
 CPPUNIT_TEST_SUITE_REGISTRATION( SALOMETraceCollectorTest );
 
 // --- generic Main program from Basic/Test
index 5f701097239e9f71de9e065508444964984cd917..a6cdbf1cd6235df12bf59e1de2db90cc3c6d23c2 100644 (file)
@@ -47,6 +47,8 @@ clt.waitLogger("Logger")
 # execute Unit Test
 
 command = ['./TestSALOMETraceCollector']
+valgrind = ['valgrind', '--leak-check=full']
+#command = valgrind+command
 ret = subprocess.call(command)
 
 # kill Test process
index 040b13db7e830d39fbd37fff6cf45229cf53bba8..3320bdfb9c1e40636da22badba4b7a536d229c29 100644 (file)
@@ -26,6 +26,7 @@
 //  $Header$
 //
 #include "TraceCollector_WaitForServerReadiness.hxx"
+#include "OpUtil.hxx"
 #include <iostream>
 #include <ctime>
 
@@ -47,8 +48,7 @@
  */
 // ============================================================================
 
-CORBA::Object_ptr TraceCollector_WaitForServerReadiness(CORBA::ORB_ptr orb,
-                                                        std::string serverName)
+CORBA::Object_ptr TraceCollector_WaitForServerReadiness(const std::string& serverName)
 {
   long TIMESleep = 500000000;
   int NumberOfTries = 40;
@@ -60,6 +60,7 @@ CORBA::Object_ptr TraceCollector_WaitForServerReadiness(CORBA::ORB_ptr orb,
   ts_rem.tv_nsec=0;
   ts_rem.tv_sec=0;
 
+  CORBA::ORB_var orb = KERNEL::GetRefToORB();
   CORBA::Object_var obj;
 
   try
index c62302bbd76a4a2f7b71e017c33eac552df07e71..177686bf08d53b2fc89908e0c896d72db5f1475a 100644 (file)
@@ -32,7 +32,6 @@
 #include <omniORB4/CORBA.h> 
 #include <string>
 
-CORBA::Object_ptr  TraceCollector_WaitForServerReadiness(CORBA::ORB_ptr theOrb,
-                                                         std::string serverName);
+CORBA::Object_ptr  TraceCollector_WaitForServerReadiness(const std::string& serverName);
 
 #endif
index d5fc761522c8917a0ce38c885ee7482cf23e431a..f421ea5fb42c6fc1a1f388b80150da1acfe26de1 100644 (file)
 //  Module : SALOME
 //
 #include "OpUtil.hxx"
+#include <mutex>
 
 #if !defined(SALOME_LIGHT)
 
 #include "Utils_SINGLETON.hxx"
 #include "Utils_ORB_INIT.hxx"
 
+namespace
+{
+  std::recursive_mutex mutex; //!< mutex to protect access to static data
+}
+
 UTILS_EXPORT CORBA::ORB_var KERNEL::GetRefToORB()
 {
+  std::lock_guard<std::recursive_mutex> g(mutex);  
   ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
-  CORBA::ORB_var &orb = init();
+  CORBA::ORB_var orb = init();
   return orb;
 }
 
index ab39d93757241943b89ee1d24d74a8ebcc0fdea5..73bf981d8e4550e991b4b8753d10863988a8f4e9 100644 (file)
 
 # include <string>
 # include <vector>
+#include <mutex>
 
 ORB_INIT::ORB_INIT( void ): _orb( CORBA::ORB::_nil() )
 {
 }
 
+namespace
+{
+  std::recursive_mutex mutex; //!< mutex to protect access to static data
+}
 
 ORB_INIT::~ORB_INIT()
 {
@@ -76,6 +81,7 @@ void ORB_INIT::explicit_destroy()
 CORBA::ORB_var &ORB_INIT::operator() ()
 {
   try {
+    std::lock_guard<std::recursive_mutex> g(mutex);  
     if ( CORBA::is_nil( _orb ) )
       {
         try
@@ -86,13 +92,16 @@ CORBA::ORB_var &ORB_INIT::operator() ()
             }
             std::vector<std::string> args = GetArgcArgv();
             int argc = args.size();
-            char** argv = new char*[argc];
-            for (int i = 0; i < argc; ++i)
-              argv[i] = strdup(args.at(i).c_str());
+            char** argv = argc > 0 ? new char*[argc] : nullptr;
+            for (int i = 0; i < argc; ++i) {
+              argv[i] = new char[args.at(i).size()+1];
+              strcpy(argv[i], args.at(i).c_str());
+            }
             _orb = CORBA::ORB_init( argc, argv, "omniORB4" ) ;
             for (int i = 0; i < argc; ++i)
               delete[] argv[i];
-            delete[] argv;
+            if (argc>0)
+              delete[] argv;
           }
         catch( const CORBA::Exception & )
           {