Log4cxx
  1. Log4cxx
  2. LOGCXX-196

Syslog appender destructor can cause core

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 0.10.0
    • Fix Version/s: 0.10.0
    • Component/s: Appender
    • Labels:
      None

      Description

      When the syslog appender is deleted, the application may crash.

        Activity

        Hide
        Myles Bunbury added a comment -

        I did not notice the problem anymore in revision #581885.

        Show
        Myles Bunbury added a comment - I did not notice the problem anymore in revision #581885.
        Hide
        Curt Arnold added a comment -

        The crash is due to when calling DatagramSocket::close() from ~DatagramSocket(), LogLog may be referenced after it has been destructed. The basic requirement for access to static resources in a destructor is that you have matching access in the constructor which ensures that the static object will not go out of scope before the destructor is called.

        The options to fix this would be:

        a. Remove the LOGLOG_DEBUG statement from DatagramSocket::close()
        b. Add a LOGLOG_DEBUG statement to Datagram::Datagram();
        c. Skip the LOGLOG_DEBUG statement when being called from destructor (would likely require putting body of close in a new method that is called from both the destructor and a new close method that calls LOGLOG_DEBUG).

        I don't think this particular LOGLOG_DEBUG statement is valuable enough to warrent option b or c, so I removed it in rev 581656. Please confirm that it resolves the problem.

        Show
        Curt Arnold added a comment - The crash is due to when calling DatagramSocket::close() from ~DatagramSocket(), LogLog may be referenced after it has been destructed. The basic requirement for access to static resources in a destructor is that you have matching access in the constructor which ensures that the static object will not go out of scope before the destructor is called. The options to fix this would be: a. Remove the LOGLOG_DEBUG statement from DatagramSocket::close() b. Add a LOGLOG_DEBUG statement to Datagram::Datagram(); c. Skip the LOGLOG_DEBUG statement when being called from destructor (would likely require putting body of close in a new method that is called from both the destructor and a new close method that calls LOGLOG_DEBUG). I don't think this particular LOGLOG_DEBUG statement is valuable enough to warrent option b or c, so I removed it in rev 581656. Please confirm that it resolves the problem.
        Hide
        Myles Bunbury added a comment -

        Stack trace of a core generated when the syslog appender destructor ran:

        #7 0x081c3a57 in synchronized (this=0x6f57f920, mutex1=@0x83ffab4)
        at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/synchronized.cpp:35
        #8 0x081d300a in log4cxx::helpers::LogLog::debug (msg=@0x6f57f958)
        at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/loglog.cpp:49
        #9 0x0825c42b in log4cxx::helpers::DatagramSocket::close (this=0x8942560)
        at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/datagramsocket.cpp:93
        #10 0x0825c735 in ~DatagramSocket (this=0x8942560)
        at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/datagramsocket.cpp:57
        #11 0x081bbfb1 in log4cxx::helpers::ObjectImpl::releaseRef (this=0x8942560)
        at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/objectimpl.cpp:43
        #12 0x08232fd2 in ~ObjectPtrT (this=0x893d9c0)
        at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/include/log4cxx/helpers/objectptr.h:112
        #13 0x08232fe9 in ~SyslogWriter (this=0x893d9b8)
        at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/include/log4cxx/helpers/syslogwriter.h:35
        #14 0x08230847 in log4cxx::net::SyslogAppender::close (this=0x893d6a8)
        at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/syslogappender.cpp:98
        #15 0x0823debd in log4cxx::AppenderSkeleton::finalize (this=0x893d6a8)
        at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/appenderskeleton.cpp:70
        #16 0x08231a99 in ~SyslogAppender (this=0x893d6a8)
        at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/syslogappender.cpp:89
        #17 0x081bbfb1 in log4cxx::helpers::ObjectImpl::releaseRef (this=0x893d6e8)
        at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/objectimpl.cpp:43
        #18 0x081b5636 in ~ObjectPtrT (this=0x893d53c)
        at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/include/log4cxx/helpers/objectptr.h:112
        #19 0x081caf53 in std::_Destroy<log4cxx::helpers::ObjectPtrT<log4cxx::Appender> > (
        __pointer=0x893d53c)
        at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_construct.h:107
        #20 0x081caf69 in std::__destroy_aux<log4cxx::helpers::ObjectPtrT<log4cxx::Appender>*> (
        __first=0x893d53c, __last=0x893d540)
        at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_construct.h:122
        #21 0x081caf98 in std::_Destroy<log4cxx::helpers::ObjectPtrT<log4cxx::Appender>*> (
        __first=0x893d538, __last=0x893d540)
        at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_construct.h:155
        #22 0x081cafb2 in std::Destroy<log4cxx::helpers::ObjectPtrT<log4cxx::Appender>*, log4cxx::helpers::ObjectPtrT<log4cxx::Appender> > (_first=0x893d538, __last=0x893d540)
        at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_construct.h:182
        #23 0x081caff3 in ~vector (this=0x893d4ac)
        at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_vector.h:272
        #24 0x081dd20b in ~AppenderAttachableImpl (this=0x893d4a8)
        at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/include/log4cxx/helpers/appenderattachableimpl.h:43
        #25 0x081bbfb1 in log4cxx::helpers::ObjectImpl::releaseRef (this=0x893d4c4)
        at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/objectimpl.cpp:43
        #26 0x081cb122 in ~ObjectPtrT (this=0x8640908)
        at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/include/log4cxx/helpers/objectptr.h:112
        #27 0x081c7af8 in ~Logger (this=0x86408f0)
        at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/logger.cpp:52
        #28 0x081bbfb1 in log4cxx::helpers::ObjectImpl::releaseRef (this=0x8640914)
        at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/objectimpl.cpp:43
        #29 0x081b6228 in ~ObjectPtrT (this=0x8640f04)
        at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/include/log4cxx/helpers/objectptr.h:112
        #30 0x081d0559 in ~pair (this=0x8640f00)
        at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_pair.h:69
        #31 0x081d05a9 in __gnu_cxx::new_allocator<std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> > >::destroy (this=0x6f57fd43, __p=0x8640f00)
        at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/ext/new_allocator.h:107
        #32 0x081d05dd in std::_Rb_tree<std::string, std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> >, std::_Select1st<std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> > >, std::less<std::string>, std::allocator<std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> > > >::destroy_node (this=0x863141c, __p=0x8640ef0)
        --Type <return> to continue, or q <return> to quit--
        at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_tree.h:391
        #33 0x081d0662 in std::_Rb_tree<std::string, std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> >, std::_Select1st<std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> > >, std::less<std::string>, std::allocator<std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> > > >::_M_erase (this=0x863141c, __x=0x8640ef0)
        at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_tree.h:1266
        #34 0x081d0642 in std::_Rb_tree<std::string, std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> >, std::_Select1st<std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> > >, std::less<std::string>, std::allocator<std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> > > >::_M_erase (this=0x863141c, __x=0x86368f0)
        at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_tree.h:1264
        #35 0x081d0642 in std::_Rb_tree<std::string, std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> >, std::_Select1st<std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> > >, std::less<std::string>, std::allocator<std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> > > >::_M_erase (this=0x863141c, __x=0x8637460)
        at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_tree.h:1264
        #36 0x081d0642 in std::_Rb_tree<std::string, std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> >, std::_Select1st<std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> > >, std::less<std::string>, std::allocator<std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> > > >::_M_erase (this=0x863141c, __x=0x8637a10)
        at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_tree.h:1264
        #37 0x081d071b in ~_Rb_tree (this=0x863141c)
        at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_tree.h:578
        #38 0x081d076b in ~map (this=0x863141c)
        at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_map.h:93
        #39 0x081ccfb4 in ~Hierarchy (this=0x86313f8)
        at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/hierarchy.cpp:61
        #40 0x081bbfb1 in log4cxx::helpers::ObjectImpl::releaseRef (this=0x863145c)
        at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/objectimpl.cpp:43
        #41 0x081b05d4 in ~ObjectPtrT (this=0x86334a4)
        at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/include/log4cxx/helpers/objectptr.h:112
        #42 0x081b0637 in ~DefaultRepositorySelector (this=0x86334a0)
        at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/include/log4cxx/spi/defaultrepositoryselector.h:32
        #43 0x081bbfb1 in log4cxx::helpers::ObjectImpl::releaseRef (this=0x86334a8)
        at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/objectimpl.cpp:43
        #44 0x081b0c0a in ~ObjectPtrT (this=0x83ff5d8)
        at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/include/log4cxx/helpers/objectptr.h:112
        #45 0x081afae6 in __tcf_1 ()
        at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/logmanager.cpp:52

        Show
        Myles Bunbury added a comment - Stack trace of a core generated when the syslog appender destructor ran: #7 0x081c3a57 in synchronized (this=0x6f57f920, mutex1=@0x83ffab4) at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/synchronized.cpp:35 #8 0x081d300a in log4cxx::helpers::LogLog::debug (msg=@0x6f57f958) at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/loglog.cpp:49 #9 0x0825c42b in log4cxx::helpers::DatagramSocket::close (this=0x8942560) at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/datagramsocket.cpp:93 #10 0x0825c735 in ~DatagramSocket (this=0x8942560) at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/datagramsocket.cpp:57 #11 0x081bbfb1 in log4cxx::helpers::ObjectImpl::releaseRef (this=0x8942560) at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/objectimpl.cpp:43 #12 0x08232fd2 in ~ObjectPtrT (this=0x893d9c0) at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/include/log4cxx/helpers/objectptr.h:112 #13 0x08232fe9 in ~SyslogWriter (this=0x893d9b8) at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/include/log4cxx/helpers/syslogwriter.h:35 #14 0x08230847 in log4cxx::net::SyslogAppender::close (this=0x893d6a8) at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/syslogappender.cpp:98 #15 0x0823debd in log4cxx::AppenderSkeleton::finalize (this=0x893d6a8) at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/appenderskeleton.cpp:70 #16 0x08231a99 in ~SyslogAppender (this=0x893d6a8) at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/syslogappender.cpp:89 #17 0x081bbfb1 in log4cxx::helpers::ObjectImpl::releaseRef (this=0x893d6e8) at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/objectimpl.cpp:43 #18 0x081b5636 in ~ObjectPtrT (this=0x893d53c) at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/include/log4cxx/helpers/objectptr.h:112 #19 0x081caf53 in std::_Destroy<log4cxx::helpers::ObjectPtrT<log4cxx::Appender> > ( __pointer=0x893d53c) at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_construct.h:107 #20 0x081caf69 in std::__destroy_aux<log4cxx::helpers::ObjectPtrT<log4cxx::Appender>*> ( __first=0x893d53c, __last=0x893d540) at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_construct.h:122 #21 0x081caf98 in std::_Destroy<log4cxx::helpers::ObjectPtrT<log4cxx::Appender>*> ( __first=0x893d538, __last=0x893d540) at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_construct.h:155 #22 0x081cafb2 in std:: Destroy<log4cxx::helpers::ObjectPtrT<log4cxx::Appender>*, log4cxx::helpers::ObjectPtrT<log4cxx::Appender> > ( _first=0x893d538, __last=0x893d540) at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_construct.h:182 #23 0x081caff3 in ~vector (this=0x893d4ac) at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_vector.h:272 #24 0x081dd20b in ~AppenderAttachableImpl (this=0x893d4a8) at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/include/log4cxx/helpers/appenderattachableimpl.h:43 #25 0x081bbfb1 in log4cxx::helpers::ObjectImpl::releaseRef (this=0x893d4c4) at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/objectimpl.cpp:43 #26 0x081cb122 in ~ObjectPtrT (this=0x8640908) at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/include/log4cxx/helpers/objectptr.h:112 #27 0x081c7af8 in ~Logger (this=0x86408f0) at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/logger.cpp:52 #28 0x081bbfb1 in log4cxx::helpers::ObjectImpl::releaseRef (this=0x8640914) at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/objectimpl.cpp:43 #29 0x081b6228 in ~ObjectPtrT (this=0x8640f04) at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/include/log4cxx/helpers/objectptr.h:112 #30 0x081d0559 in ~pair (this=0x8640f00) at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_pair.h:69 #31 0x081d05a9 in __gnu_cxx::new_allocator<std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> > >::destroy (this=0x6f57fd43, __p=0x8640f00) at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/ext/new_allocator.h:107 #32 0x081d05dd in std::_Rb_tree<std::string, std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> >, std::_Select1st<std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> > >, std::less<std::string>, std::allocator<std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> > > >::destroy_node (this=0x863141c, __p=0x8640ef0) -- Type <return> to continue, or q <return> to quit -- at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_tree.h:391 #33 0x081d0662 in std::_Rb_tree<std::string, std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> >, std::_Select1st<std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> > >, std::less<std::string>, std::allocator<std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> > > >::_M_erase (this=0x863141c, __x=0x8640ef0) at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_tree.h:1266 #34 0x081d0642 in std::_Rb_tree<std::string, std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> >, std::_Select1st<std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> > >, std::less<std::string>, std::allocator<std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> > > >::_M_erase (this=0x863141c, __x=0x86368f0) at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_tree.h:1264 #35 0x081d0642 in std::_Rb_tree<std::string, std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> >, std::_Select1st<std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> > >, std::less<std::string>, std::allocator<std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> > > >::_M_erase (this=0x863141c, __x=0x8637460) at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_tree.h:1264 #36 0x081d0642 in std::_Rb_tree<std::string, std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> >, std::_Select1st<std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> > >, std::less<std::string>, std::allocator<std::pair<std::string const, log4cxx::helpers::ObjectPtrT<log4cxx::Logger> > > >::_M_erase (this=0x863141c, __x=0x8637a10) at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_tree.h:1264 #37 0x081d071b in ~_Rb_tree (this=0x863141c) at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_tree.h:578 #38 0x081d076b in ~map (this=0x863141c) at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_map.h:93 #39 0x081ccfb4 in ~Hierarchy (this=0x86313f8) at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/hierarchy.cpp:61 #40 0x081bbfb1 in log4cxx::helpers::ObjectImpl::releaseRef (this=0x863145c) at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/objectimpl.cpp:43 #41 0x081b05d4 in ~ObjectPtrT (this=0x86334a4) at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/include/log4cxx/helpers/objectptr.h:112 #42 0x081b0637 in ~DefaultRepositorySelector (this=0x86334a0) at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/include/log4cxx/spi/defaultrepositoryselector.h:32 #43 0x081bbfb1 in log4cxx::helpers::ObjectImpl::releaseRef (this=0x86334a8) at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/objectimpl.cpp:43 #44 0x081b0c0a in ~ObjectPtrT (this=0x83ff5d8) at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/include/log4cxx/helpers/objectptr.h:112 #45 0x081afae6 in __tcf_1 () at /home/mbunbury/log4cxx/log4cxx-0.10.0/src/main/cpp/logmanager.cpp:52

          People

          • Assignee:
            Curt Arnold
            Reporter:
            Myles Bunbury
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development