[Ace-users] [ace-users] ACE_Singleton and StructuredEvent causes segfault on exit

Douglas C. Schmidt schmidt at dre.vanderbilt.edu
Wed Jan 16 10:21:25 CST 2008


Hi Christian,

   Thanks for using the PRF.

>    ACE VERSION: 5.6
>
>    HOST MACHINE and OPERATING SYSTEM: Redhat Enterprise Linux 4.2
>
>    TARGET MACHINE and OPERATING SYSTEM, if different from HOST:
>    COMPILER NAME AND VERSION (AND PATCHLEVEL): GCC 3.4.4
>
>    THE $ACE_ROOT/ace/config.h FILE:
>        #define ACE_HAS_VALGRIND 1
>        #define ACE_HAS_ICMP_SUPPORT 1
>        #include "config-linux.h"
>        #undef ACE_LACKS_MKSTEMP_PROTOTYPE
>
>    THE $ACE_ROOT/include/makeinclude/platform_macros.GNU FILE:
>        platform_linux.GNU
>
>    CONTENTS OF $ACE_ROOT/bin/MakeProjectCreator/config/
>default.features:
>        Default Contents
>
>    AREA/CLASS/EXAMPLE AFFECTED: ACE_Singleton and StructuredEvent
>
>    DOES THE PROBLEM AFFECT: EXECUTION
>
>    SYNOPSIS:
>       StructuredEvent stored inside an ACE_Singleton causes segfault
>       on exit/cleanup.
>
>    DESCRIPTION:
>       Storing a StructuredEvent inside an ACE_Singleton, and putting
>something
>       in the remainder_of_body causes a segmentation fault on
>returning
>       from main (during exit/cleanup).

Right, this is occurring because the ORB (and its associated
datastructures) are being destroyed before the ACE_Singleton runs.  I
recommend that you consider using the ACE_Unmanaged_Singleton and
explicitly delete it before you exit main.

Thanks,

        Doug

>--- Backtrace of SegFault ---
>
>[christian at gyoza StructuredEvent]$ gdb TestEvent
>GNU gdb Red Hat Linux (6.3.0.0-1.63rh)
>Copyright 2004 Free Software Foundation, Inc.
>GDB is free software, covered by the GNU General Public License, and
>you are
>welcome to change it and/or distribute copies of it under certain
>conditions.
>Type "show copying" to see the conditions.
>There is absolutely no warranty for GDB.  Type "show warranty" for
>details.
>This GDB was configured as "i386-redhat-linux-gnu"...Using host
>libthread_db library "/lib/tls/libthread_db.so.1".
>
>(gdb) run
>Starting program: /home/christian/test/StructuredEvent/TestEvent
>Reading symbols from shared object read from target memory...done.
>Loaded system supplied DSO at 0x2c9000
>[Thread debugging using libthread_db enabled]
>[New Thread -1215997728 (LWP 15561)]
>pure virtual method called
>terminate called without an active exception
>
>Program received signal SIGABRT, Aborted.
>[Switching to Thread -1215997728 (LWP 15561)]
>0x002c9402 in __kernel_vsyscall ()
>(gdb) bt
>#0  0x002c9402 in __kernel_vsyscall ()
>#1  0x0030a7d5 in raise () from /lib/tls/libc.so.6
>#2  0x0030c149 in abort () from /lib/tls/libc.so.6
>#3  0x0063725e in __gnu_cxx::__verbose_terminate_handler () from /usr/
>lib/libstdc++.so.6
>#4  0x00634ef1 in __cxa_call_unexpected () from /usr/lib/libstdc++.so.
>6
>#5  0x00634f26 in std::terminate () from /usr/lib/libstdc++.so.6
>#6  0x006355d5 in __cxa_pure_virtual () from /usr/lib/libstdc++.so.6
>#7  0xb7a8e592 in CORBA::release (obj=0xb79ccb74)
>    at /home/christian/COTS/ACE_5.6.1_debug/ACE_wrappers/TAO/tao/
>AnyTypeCode/TypeCode.inl:17
>#8  0xb7941e65 in TAO::Any_Impl::free_value (this=0x971a5c8) at
>AnyTypeCode/Any_Impl.cpp:48
>#9  0xb7941fb0 in TAO::Any_Impl::_remove_ref (this=0x971a5c8) at
>AnyTypeCode/Any_Impl.cpp:104
>#10 0xb79396b2 in CORBA::Any::~Any ()
>    at /home/christian/COTS/ACE_5.6.1_debug/ACE_wrappers/TAO/tao/
>SystemException.inl:112
>#11 0x08049686 in ~StructuredEvent (this=0x971a55c) at TestEvent.cpp:
>11
>#12 0x08049a43 in ~SingletonImpl (this=0x971a55c) at TestEvent.cpp:17
>#13 0x08049a67 in ~ACE_Singleton (this=0x971a558) at TestEvent.cpp:77
>#14 0x08049ada in ACE_Singleton<SingletonImpl,
>ACE_Null_Mutex>::cleanup (this=0x971a558)
>    at /home/christian/COTS/ACE_5.6.1_debug/ACE_wrappers/ace/
>Singleton.cpp:111
>#15 0xb7e56917 in ace_cleanup_destroyer (object=0x971a558, param=0x0)
>at Cleanup.cpp:33
>#16 0xb7e56e11 in ACE_OS_Exit_Info::call_hooks (this=0x9715138) at
>Cleanup.cpp:181
>#17 0xb7e8eb0e in ACE_Object_Manager::fini (this=0x9715128) at
>Object_Manager.cpp:609
>#18 0xb7e8df5e in ~ACE_Object_Manager (this=0x9715128) at
>Object_Manager.cpp:318
>#19 0xb7e8ef1c in ~ACE_Object_Manager_Manager (this=0xb7f36890) at
>Object_Manager.cpp:765
>#20 0xb7e8f0dc in __tcf_0 () at Object_Manager.cpp:773
>#21 0x0030d6e4 in __cxa_finalize () from /lib/tls/libc.so.6
>#22 0xb7e080ce in __do_global_dtors_aux () from /home/christian/COTS/
>ACE_5.6.1_debug/ACE_wrappers/lib/libACE.so.5.6.0
>#23 0xb7ee15f6 in _fini () from /home/christian/COTS/ACE_5.6.1_debug/
>ACE_wrappers/lib/libACE.so.5.6.0
>#24 0x002d6887 in _dl_fini () from /lib/ld-linux.so.2
>#25 0x0030d467 in exit () from /lib/tls/libc.so.6
>#26 0x002f7e2d in __libc_start_main () from /lib/tls/libc.so.6
>#27 0x08049169 in _start ()
>(gdb) quit
>
>--- End Backtrace ---
>
>    REPEAT BY:
>
>--- Test Program ---
>
>#include <orbsvcs/CosNotificationC.h>
>#include <ace/Singleton.h>
>#include <list>
>
>class SingletonImpl
>{
>private:
>   friend class ACE_Singleton<SingletonImpl, ACE_Null_Mutex>;
>
>   SingletonImpl()
>   {
>      CORBA::Long testVal=1234L;
>      m_event.remainder_of_body <<= testVal;
>   }
>
>   ~SingletonImpl()
>   {
>   }
>
>   CosNotification::StructuredEvent m_event;
>};
>
>typedef ACE_Singleton<SingletonImpl, ACE_Null_Mutex> SingletonTest;
>
>int main(int argc, char* argv[])
>{
>   SingletonTest::instance();
>   return 0;
>}
>
>--- End Test Program ---
>
>    SAMPLE FIX/WORKAROUND: Manually destroy singleton before exiting
>main.
>


-- 
Dr. Douglas C. Schmidt                       Professor and Associate Chair
Electrical Engineering and Computer Science  TEL: (615) 343-8197
Vanderbilt University                        WEB: www.dre.vanderbilt.edu/~schmidt
Nashville, TN 37203                          NET: d.schmidt at vanderbilt.edu



More information about the Ace-users mailing list