Skip to content

Fix memory leak by incorrect assignment of Intrusive_Auto_Ptr.#2

Merged
jwillemsen merged 3 commits intoDOCGroup:masterfrom
likema:feature/fix-mem-leak-intrusive-ptr
Jan 12, 2015
Merged

Fix memory leak by incorrect assignment of Intrusive_Auto_Ptr.#2
jwillemsen merged 3 commits intoDOCGroup:masterfrom
likema:feature/fix-mem-leak-intrusive-ptr

Conversation

@likema
Copy link
Copy Markdown
Contributor

@likema likema commented Jan 11, 2015

No description provided.

@jwillemsen
Copy link
Copy Markdown
Member

Please extend or add a new test under ACE/tests that reproduces this issue automatically which we can we use to validate the problem and also that makes sure the issue doesn't get introduced back in the future.

@likema
Copy link
Copy Markdown
Contributor Author

likema commented Jan 11, 2015

OK, done.

@likema
Copy link
Copy Markdown
Contributor Author

likema commented Jan 11, 2015

Before fixing it, the new test will be crashed. Now, it passed.

@jwillemsen
Copy link
Copy Markdown
Member

Thanks, as last request please add some documentation to the class and test to explain the behavior and what the test expects

@likema
Copy link
Copy Markdown
Contributor Author

likema commented Jan 12, 2015

Since the class already had straightforward docs, I just added docs for the unit test.

@jwillemsen
Copy link
Copy Markdown
Member

Did a local test and reviewed the changes, will merge this, thanks for making the fix and extending the test.

jwillemsen added a commit that referenced this pull request Jan 12, 2015
Fix memory leak by incorrect assignment of Intrusive_Auto_Ptr.
@jwillemsen jwillemsen merged commit dcb2082 into DOCGroup:master Jan 12, 2015
@likema likema deleted the feature/fix-mem-leak-intrusive-ptr branch January 12, 2015 08:55
mcorino pushed a commit that referenced this pull request May 31, 2015
mitza-oci pushed a commit that referenced this pull request Aug 14, 2020
updated GitHub Actions build names
fklassen added a commit to appneta/ACE_TAO that referenced this pull request Nov 16, 2022
Under extreme multi-thread log load tests found that occasionally two threads
would lock up on macOS, with one thread reporting EXC_BAD_ACCESS. In our load
test environment this happened after about 20 hours of testing.

This patch ensures that no log messages are written at the same time as
this->log_msg_->msg_ostream()->tell()`

Stack trace of log rotation thread getting EXC_BAD_ACCESS on `fwrite()` due to
`this->log_msg_->msg_ostream()->tell()`:

```
* thread DOCGroup#1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x00007ff81884b222 libsystem_platform.dylib`_platform_memmove$VARIANT$Haswell + 194
    frame DOCGroup#1: 0x00007ff81870833b libsystem_c.dylib`__sfvwrite + 382
    frame DOCGroup#2: 0x00007ff818729d0c libsystem_c.dylib`fwrite + 136
    frame DOCGroup#3: 0x0000000106a3dabe NetSequencer`std::__1::basic_filebuf<char, std::__1::char_traits<char> >::overflow(this=0x00007f80f3204328, __c=-1) at fstream:823:17
    frame DOCGroup#4: 0x0000000106a3cf31 NetSequencer`std::__1::basic_filebuf<char, std::__1::char_traits<char> >::sync(this=0x00007f80f3204328) at fstream:988:17
    frame DOCGroup#5: 0x0000000106a3caf8 NetSequencer`std::__1::basic_filebuf<char, std::__1::char_traits<char> >::seekoff(this=0x00007f80f3204328, __off=0, __way=cur, (null)=16) at fstream:928:63
    frame DOCGroup#6: 0x0000000107b122c3 NetSequencer`std::__1::basic_streambuf<char, std::__1::char_traits<char> >::pubseekoff(this=0x00007f80f3204328, __off=0, __way=cur, __which=16) at streambuf:159:14
    frame DOCGroup#7: 0x0000000107b1109b NetSequencer`std::__1::basic_ostream<char, std::__1::char_traits<char> >::tellp(this=0x00007f80f3204320) at ostream:960:27
    frame DOCGroup#8: 0x0000000107b10b97 NetSequencer`ACE_Logging_Strategy::handle_timeout(this=0x00006000012f01b0, (null)=0x00007ff7b94f67d0, (null)=0x0000000000000000) at Logging_Strategy.cpp:432:48
    frame DOCGroup#9: 0x0000000107af7ac2 NetSequencer`ACE_Event_Handler_Handle_Timeout_Upcall::timeout(this=0x00006000022c8020, timer_queue=0x00007f80f32041c0, event_handler=0x00006000012f01b0, act=0x0000000000000000, recurring_timer=1, cur_time=0x00007ff7b94f67d0) at Event_Handler_Handle_Timeout_Upcall.cpp:42:22
    frame DOCGroup#10: 0x0000000107b38598 NetSequencer`ACE_Timer_Queue_T<ACE_Event_Handler*, ACE_Event_Handler_Handle_Timeout_Upcall, ACE_Recursive_Thread_Mutex, ACE_FPointer_Time_Policy>::upcall(this=0x00007f80f32041c0, info=0x00007ff7b94f6720, cur_time=0x00007ff7b94f67d0) at Timer_Queue_T.inl:36:27
    frame DOCGroup#11: 0x0000000107b35702 NetSequencer`ACE_Timer_Queue_T<ACE_Event_Handler*, ACE_Event_Handler_Handle_Timeout_Upcall, ACE_Recursive_Thread_Mutex, ACE_FPointer_Time_Policy>::expire(this=0x00007f80f32041c0, cur_time=0x00007ff7b94f67d0) at Timer_Queue_T.cpp:289:13
    frame DOCGroup#12: 0x0000000107b3581f NetSequencer`ACE_Timer_Queue_T<ACE_Event_Handler*, ACE_Event_Handler_Handle_Timeout_Upcall, ACE_Recursive_Thread_Mutex, ACE_FPointer_Time_Policy>::expire(this=0x00007f80f32041c0) at Timer_Queue_T.cpp:258:16
    frame DOCGroup#13: 0x0000000107b33a41 NetSequencer`ACE_Select_Reactor_T<ACE_Reactor_Token_T<ACE_Token> >::dispatch_timer_handlers(this=0x00007f80e2808e00, number_of_handlers_dispatched=0x00007ff7b94f6838) at Select_Reactor_T.cpp:1153:56
    frame DOCGroup#14: 0x0000000107b33932 NetSequencer`ACE_Select_Reactor_T<ACE_Reactor_Token_T<ACE_Token> >::dispatch(this=0x00007f80e2808e00, active_handle_count=0, dispatch_set=0x00007f80e2808e38) at Select_Reactor_T.cpp:1348:22
    frame DOCGroup#15: 0x0000000107b3acb2 NetSequencer`ACE_Select_Reactor_T<ACE_Reactor_Token_T<ACE_Token> >::handle_events_i(this=0x00007f80e2808e00, max_wait_time=0x0000000000000000) at Select_Reactor_T.cpp:1463:15
    frame DOCGroup#16: 0x0000000107b306de NetSequencer`ACE_Select_Reactor_T<ACE_Reactor_Token_T<ACE_Token> >::handle_events(this=0x00007f80e2808e00, max_wait_time=0x0000000000000000) at Select_Reactor_T.cpp:1439:16
    frame DOCGroup#17: 0x0000000107b2e859 NetSequencer`ACE_Reactor::run_reactor_event_loop(this=0x00006000020f4540, eh=0x0000000000000000)(ACE_Reactor*)) at Reactor.cpp:218:49
    frame DOCGroup#18: 0x0000000106ab72c5 NetSequencer`SeqNetServer::go(this=0x00007f80f312da48) at Server.cpp:215:49
    ...
    ```

    Another thread that is stuck on `fwrite()` when attempting to log during log rotation:

    ```
        thread DOCGroup#7, name = 'TestMaster'
        frame #0: 0x00007ff8187fdbd2 libsystem_kernel.dylib`__psynch_mutexwait + 10
        frame DOCGroup#1: 0x00007ff818835e7e libsystem_pthread.dylib`_pthread_mutex_firstfit_lock_wait + 76
        frame DOCGroup#2: 0x00007ff818833cbb libsystem_pthread.dylib`_pthread_mutex_firstfit_lock_slow + 205
        frame DOCGroup#3: 0x00007ff818714ae8 libsystem_c.dylib`flockfile + 31
        frame DOCGroup#4: 0x00007ff818729cc6 libsystem_c.dylib`fwrite + 66
        frame DOCGroup#5: 0x0000000106a3dabe NetSequencer`std::__1::basic_filebuf<char, std::__1::char_traits<char> >::overflow(this=0x00007f80f3204328, __c=49) at fstream:823:17
        frame DOCGroup#6: 0x00007ff8187a27c1 libc++.1.dylib`std::__1::basic_streambuf<char, std::__1::char_traits<char> >::xsputn(char const*, long) + 109
        frame DOCGroup#7: 0x0000000106a3f9a6 NetSequencer`std::__1::basic_streambuf<char, std::__1::char_traits<char> >::sputn(this=0x00007f80f3204328, __s="NTC (58424|123145504292864|2022-11-16 05:41:53.094817 HopTracerouteData::getRtts) testId=_42147-1GHN9QEGN_76601, ttl=10, pkt 3403, sendSize=92, recvSize=0, rtt=0, send=1668606099528987, recv=0\n", __n=193) at streambuf:229:14
        frame DOCGroup#8: 0x0000000106a3f821 NetSequencer`std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > std::__1::__pad_and_output<char, std::__1::char_traits<char> >(__s=ostreambuf_iterator<char, std::__1::char_traits<char> > @ 0x000070000c09c190, __ob="NTC (58424|123145504292864|2022-11-16 05:41:53.094817 HopTracerouteData::getRtts) testId=_42147-1GHN9QEGN_76601, ttl=10, pkt 3403, sendSize=92, recvSize=0, rtt=0, send=1668606099528987, recv=0\n", __op="NTC (58424|123145504292864|2022-11-16 05:41:53.094817 HopTracerouteData::getRtts) testId=_42147-1GHN9QEGN_76601, ttl=10, pkt 3403, sendSize=92, recvSize=0, rtt=0, send=1668606099528987, recv=0\n", __oe="", __iob=0x00007f80f3204320, __fl=32 ' ') at locale:1428:26
        frame DOCGroup#9: 0x0000000106a3f4fa NetSequencer`std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(__os=0x00007f80f3204320, __str="NTC (58424|123145504292864|2022-11-16 05:41:53.094817 HopTracerouteData::getRtts) testId=_42147-1GHN9QEGN_76601, ttl=10, pkt 3403, sendSize=92, recvSize=0, rtt=0, send=1668606099528987, recv=0\n", __len=193) at ostream:718:17
        frame DOCGroup#10: 0x0000000106abfaf9 NetSequencer`std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<<<std::__1::char_traits<char> >(__os=0x00007f80f3204320, __str="NTC (58424|123145504292864|2022-11-16 05:41:53.094817 HopTracerouteData::getRtts) testId=_42147-1GHN9QEGN_76601, ttl=10, pkt 3403, sendSize=92, recvSize=0, rtt=0, send=1668606099528987, recv=0\n") at ostream:857:12
        frame DOCGroup#11: 0x0000000107b0eb7a NetSequencer`ACE_Log_Record::print(this=0x000070000c09cf20, host_name=0x0000000000000000, verbose_flag=5, s=0x00007f80f3204320) at Log_Record.cpp:427:13
        frame DOCGroup#12: 0x0000000107b0b81d NetSequencer`ACE_Log_Msg::log(this=0x00007f810400c000, log_record=0x000070000c09cf20, suppress_stderr=0) at Log_Msg.cpp:2932:20
        frame DOCGroup#13: 0x0000000107b0aed9 NetSequencer`ACE_Log_Msg::log(this=0x00007f810400c000, format_str="", log_priority=LM_NOTICE, argp=0x000070000c09e1b0, category=0x0000000000000000) at Log_Msg.cpp:2200:22
        frame DOCGroup#14: 0x000000010750e196 NetSequencer`APN::LogUtil::log(logPriority=LM_NOTICE, formatStr="NTC%I (%P|%t|%D HopTracerouteData::getRtts) testId=%s, ttl=%u, pkt %u, sendSize=%u, recvSize=%u, rtt=%u, send=%Q, recv=%Q\n") at macros.cpp:44:19
...
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants