Menu

#738 Segmentation fault after batch build

Release_xx.yy
fixed
Batch build (2)
Bug_Report
2018-12-15
2018-09-19
No

When you close the window after completing a batch build there is a segmentation fault. This happens because there is no log to clear when closing the workspace. The backtrace is here:
http://forums.codeblocks.org/index.php/topic,22824.msg155109.html#msg155109

This patch fixes this issue.

1 Attachments

Discussion

  • Miguel Gimenez

    Miguel Gimenez - 2018-10-07

    After revision 11499 the patch should be this

     
  • Teodor Petrov

    Teodor Petrov - 2018-10-07
    • assigned_to: Teodor Petrov
     
  • Teodor Petrov

    Teodor Petrov - 2018-10-07

    No this is not the correct patch. This just hides the problem. The real problem is that the info pane is gone by the time this code is executed.

     
  • Teodor Petrov

    Teodor Petrov - 2018-10-07

    Here is the log from asan which shows what the real problem is.
    We need to find a way to destroy the frame later. I guess we need to use some timer events or something similar and implement some kind of a state machine. But I'm not really sure what to do.

    =================================================================
    ==6160==ERROR: AddressSanitizer: heap-use-after-free on address 0x61b0001988b8 at pc 0x7ffff1a4428c bp 0x7fffffffbaa0 sp 0x7fffffffba90
    READ of size 8 at 0x61b0001988b8 thread T0
        #0 0x7ffff1a4428b in TextCtrlLogger::Clear() /home/obfuscated/projects/codeblocks/git/src/sdk/loggers.cpp:165
        #1 0x7fffe3e3a14a in CompilerGCC::ClearLog(bool) /home/obfuscated/projects/codeblocks/git/src/plugins/compilergcc/compilergcc.cpp:1070
        #2 0x7fffe3e564fe in CompilerGCC::OnWorkspaceClosed(CodeBlocksEvent&) /home/obfuscated/projects/codeblocks/git/src/plugins/compilergcc/compilergcc.cpp:3411
        #3 0x7fffe3e74e34 in cbEventFunctor<CompilerGCC, CodeBlocksEvent>::Call(CodeBlocksEvent&) /home/obfuscated/projects/codeblocks/git/src/include/cbfunctor.h:49
        #4 0x7ffff1a5e127 in Manager::ProcessEvent(CodeBlocksEvent&) /home/obfuscated/projects/codeblocks/git/src/sdk/manager.cpp:260
        #5 0x7ffff1aa1966 in PluginManager::NotifyPlugins(CodeBlocksEvent&) /home/obfuscated/projects/codeblocks/git/src/sdk/pluginmanager.cpp:1522
        #6 0x7ffff1aef4d4 in ProjectManager::CloseWorkspace() /home/obfuscated/projects/codeblocks/git/src/sdk/projectmanager.cpp:620
        #7 0x55555579439c in MainFrame::DoCloseCurrentWorkspace() /home/obfuscated/projects/codeblocks/git/src/src/main.cpp:1877
        #8 0x5555557a0de4 in MainFrame::OnApplicationClose(wxCloseEvent&) /home/obfuscated/projects/codeblocks/git/src/src/main.cpp:2758
        #9 0x7ffff267aaa4 in wxAppConsoleBase::HandleEvent(wxEvtHandler*, void (wxEvtHandler::*)(wxEvent&), wxEvent&) const ../git/src/common/appbase.cpp:657
        #10 0x7ffff267ab17 in wxAppConsoleBase::CallEventHandler(wxEvtHandler*, wxEventFunctor&, wxEvent&) const ../git/src/common/appbase.cpp:669
        #11 0x7ffff27a7615 in wxEvtHandler::ProcessEventIfMatchesId(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) ../git/src/common/event.cpp:1396
        #12 0x7ffff27a638e in wxEventHashTable::HandleEvent(wxEvent&, wxEvtHandler*) ../git/src/common/event.cpp:1004
        #13 0x7ffff27a7b1a in wxEvtHandler::TryHereOnly(wxEvent&) ../git/src/common/event.cpp:1593
        #14 0x7ffff27a9602 in wxEvtHandler::TryBeforeAndHere(wxEvent&) ../git/include/wx/event.h:3890
        #15 0x7ffff27a78a1 in wxEvtHandler::ProcessEvent(wxEvent&) ../git/src/common/event.cpp:1495
        #16 0x7ffff27a79b9 in wxEvtHandler::DoTryChain(wxEvent&) ../git/src/common/event.cpp:1558
        #17 0x7ffff27a7935 in wxEvtHandler::ProcessEventLocally(wxEvent&) ../git/src/common/event.cpp:1526
        #18 0x7ffff27a78b6 in wxEvtHandler::ProcessEvent(wxEvent&) ../git/src/common/event.cpp:1499
        #19 0x7ffff27a7bca in wxEvtHandler::SafelyProcessEvent(wxEvent&) ../git/src/common/event.cpp:1617
        #20 0x7ffff33f631d in wxWindowBase::HandleWindowEvent(wxEvent&) const ../git/src/common/wincmn.cpp:1539
        #21 0x7ffff33f3833 in wxWindowBase::Close(bool) ../git/src/common/wincmn.cpp:588
        #22 0x5555556b0ede in CodeBlocksApp::OnInit() /home/obfuscated/projects/codeblocks/git/src/src/app.cpp:742
        #23 0x5555556be2ed in wxAppConsoleBase::CallOnInit() (/home/obfuscated/projects/codeblocks/git/src/devel30/codeblocks+0x16a2ed)
        #24 0x7ffff26ee155 in wxEntry(int&, wchar_t**) ../git/src/common/init.cpp:491
        #25 0x7ffff26ee25c in wxEntry(int&, char**) ../git/src/common/init.cpp:519
        #26 0x5555556ad918 in main /home/obfuscated/projects/codeblocks/git/src/src/app.cpp:338
        #27 0x7ffff02d4bdd in __libc_start_main (/lib64/libc.so.6+0x21bdd)
        #28 0x5555556ac2c9 in _start (/home/obfuscated/projects/codeblocks/git/src/devel30/codeblocks+0x1582c9)
    
    0x61b0001988b8 is located 1336 bytes inside of 1416-byte region [0x61b000198380,0x61b000198908)
    freed by thread T0 here:
        #0 0x7ffff6efeba0 in operator delete(void*, unsigned long) (/usr/lib/gcc/x86_64-pc-linux-gnu/6.4.0/libasan.so.3+0xc8ba0)
        #1 0x7ffff32a49d6 in wxTextCtrl::~wxTextCtrl() ../git/src/gtk/textctrl.cpp:671
        #2 0x7ffff33f379a in wxWindowBase::Destroy() ../git/src/common/wincmn.cpp:575
        #3 0x7ffff33f3933 in wxWindowBase::DestroyChildren() ../git/src/common/wincmn.cpp:607
        #4 0x7ffff3211377 in wxWindow::~wxWindow() ../git/src/gtk/window.cpp:2728
        #5 0x7ffff3265623 in wxNavigationEnabled<wxWindow>::~wxNavigationEnabled() ../git/include/wx/containr.h:192
        #6 0x7ffff32656ab in wxPanelBase::~wxPanelBase() ../git/include/wx/panel.h:30
        #7 0x7ffff331bb3f in wxPanel::~wxPanel() ../git/include/wx/generic/panelg.h:16
        #8 0x7ffff331bb5b in wxPanel::~wxPanel() ../git/include/wx/generic/panelg.h:16
        #9 0x7ffff33f379a in wxWindowBase::Destroy() ../git/src/common/wincmn.cpp:575
        #10 0x7ffff470c4b5 in wxAuiNotebook::DeletePage(unsigned long) ../git/src/aui/auibook.cpp:2024
        #11 0x7ffff470b839 in wxAuiNotebook::~wxAuiNotebook() ../git/src/aui/auibook.cpp:1731
        #12 0x7ffff186bbc6 in cbAuiNotebook::~cbAuiNotebook() /home/obfuscated/projects/codeblocks/git/src/sdk/cbauibook.cpp:80
        #13 0x5555557751f7 in InfoPane::~InfoPane() /home/obfuscated/projects/codeblocks/git/src/src/infopane.cpp:61
        #14 0x555555775223 in InfoPane::~InfoPane() /home/obfuscated/projects/codeblocks/git/src/src/infopane.cpp:68
        #15 0x7ffff33f379a in wxWindowBase::Destroy() ../git/src/common/wincmn.cpp:575
        #16 0x7ffff33f3933 in wxWindowBase::DestroyChildren() ../git/src/common/wincmn.cpp:607
        #17 0x7ffff3211377 in wxWindow::~wxWindow() ../git/src/gtk/window.cpp:2728
        #18 0x7ffff31f94db in wxNonOwnedWindowBase::~wxNonOwnedWindowBase() ../git/include/wx/nonownedwnd.h:25
        #19 0x7ffff31f8fee in wxNonOwnedWindow::~wxNonOwnedWindow() ../git/src/gtk/nonownedwnd.cpp:216
        #20 0x7ffff33e7960 in wxTopLevelWindowBase::~wxTopLevelWindowBase() ../git/src/common/toplvcmn.cpp:61
        #21 0x7ffff3205910 in wxTopLevelWindowGTK::~wxTopLevelWindowGTK() ../git/src/gtk/toplevel.cpp:809
        #22 0x7ffff31c2a73 in wxTopLevelWindow::~wxTopLevelWindow() ../git/include/wx/toplevel.h:383
        #23 0x7ffff31c2adb in wxNavigationEnabled<wxTopLevelWindow>::~wxNavigationEnabled() ../git/include/wx/containr.h:192
        #24 0x7ffff31c2b47 in wxDialogBase::~wxDialogBase() ../git/include/wx/dialog.h:68
        #25 0x7ffff326ab72 in wxDialog::~wxDialog() ../git/src/gtk/dialog.cpp:79
        #26 0x5555556e7448 in wxScrollingDialog::~wxScrollingDialog() /home/obfuscated/projects/codeblocks/git/src/include/scrollingdialog.h:163
        #27 0x5555557dfe08 in BatchLogWindow::~BatchLogWindow() /home/obfuscated/projects/codeblocks/git/src/src/batchbuild.h:15
        #28 0x5555557dfe23 in BatchLogWindow::~BatchLogWindow() /home/obfuscated/projects/codeblocks/git/src/src/batchbuild.h:15
        #29 0x7ffff267a9f7 in wxAppConsoleBase::DeletePendingObjects() ../git/src/common/appbase.cpp:637
    
    previously allocated by thread T0 here:
        #0 0x7ffff6efdea0 in operator new(unsigned long) (/usr/lib/gcc/x86_64-pc-linux-gnu/6.4.0/libasan.so.3+0xc7ea0)
        #1 0x7ffff1a44436 in TextCtrlLogger::CreateControl(wxWindow*) /home/obfuscated/projects/codeblocks/git/src/sdk/loggers.cpp:171
        #2 0x7fffe3e6a736 in BuildLogger::CreateControl(wxWindow*) (/home/obfuscated/projects/codeblocks/git/src/devel30/share/codeblocks/plugins/libcompiler.so+0x128736)
        #3 0x5555557b4a81 in MainFrame::OnAddLogWindow(CodeBlocksLogEvent&) /home/obfuscated/projects/codeblocks/git/src/src/main.cpp:5006
        #4 0x5555557e0452 in cbEventFunctor<MainFrame, CodeBlocksLogEvent>::Call(CodeBlocksLogEvent&) (/home/obfuscated/projects/codeblocks/git/src/devel30/codeblocks+0x28c452)
        #5 0x7ffff1a5e8ee in Manager::ProcessEvent(CodeBlocksLogEvent&) /home/obfuscated/projects/codeblocks/git/src/sdk/manager.cpp:328
        #6 0x7fffe3e30ffd in CompilerGCC::OnAttach() /home/obfuscated/projects/codeblocks/git/src/plugins/compilergcc/compilergcc.cpp:391
        #7 0x7ffff18b5601 in cbPlugin::Attach() /home/obfuscated/projects/codeblocks/git/src/sdk/cbplugin.cpp:73
        #8 0x7ffff1a93d02 in PluginManager::AttachPlugin(cbPlugin*, bool) /home/obfuscated/projects/codeblocks/git/src/sdk/pluginmanager.cpp:197
        #9 0x7ffff1a9e155 in PluginManager::LoadAllPlugins() /home/obfuscated/projects/codeblocks/git/src/sdk/pluginmanager.cpp:1108
        #10 0x55555578a09f in MainFrame::ScanForPlugins() /home/obfuscated/projects/codeblocks/git/src/src/main.cpp:1204
        #11 0x555555781002 in MainFrame::MainFrame(wxWindow*) /home/obfuscated/projects/codeblocks/git/src/src/main.cpp:627
        #12 0x5555556ae300 in CodeBlocksApp::InitFrame() /home/obfuscated/projects/codeblocks/git/src/src/app.cpp:505
        #13 0x5555556b0aaa in CodeBlocksApp::OnInit() /home/obfuscated/projects/codeblocks/git/src/src/app.cpp:716
        #14 0x5555556be2ed in wxAppConsoleBase::CallOnInit() (/home/obfuscated/projects/codeblocks/git/src/devel30/codeblocks+0x16a2ed)
        #15 0x7ffff26ee155 in wxEntry(int&, wchar_t**) ../git/src/common/init.cpp:491
        #16 0x7ffff26ee25c in wxEntry(int&, char**) ../git/src/common/init.cpp:519
        #17 0x5555556ad918 in main /home/obfuscated/projects/codeblocks/git/src/src/app.cpp:338
        #18 0x7ffff02d4bdd in __libc_start_main (/lib64/libc.so.6+0x21bdd)
    
    SUMMARY: AddressSanitizer: heap-use-after-free /home/obfuscated/projects/codeblocks/git/src/sdk/loggers.cpp:165 in TextCtrlLogger::Clear()
    Shadow bytes around the buggy address:
      0x0c368002b0c0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      0x0c368002b0d0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      0x0c368002b0e0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      0x0c368002b0f0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      0x0c368002b100: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
    =>0x0c368002b110: fd fd fd fd fd fd fd[fd]fd fd fd fd fd fd fd fd
      0x0c368002b120: fd fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
      0x0c368002b130: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
      0x0c368002b140: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
      0x0c368002b150: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      0x0c368002b160: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
    Shadow byte legend (one shadow byte represents 8 application bytes):
      Addressable:           00
      Partially addressable: 01 02 03 04 05 06 07
      Heap left redzone:       fa
      Heap right redzone:      fb
      Freed heap region:       fd
      Stack left redzone:      f1
      Stack mid redzone:       f2
      Stack right redzone:     f3
      Stack partial redzone:   f4
      Stack after return:      f5
      Stack use after scope:   f8
      Global redzone:          f9
      Global init order:       f6
      Poisoned by user:        f7
      Container overflow:      fc
      Array cookie:            ac
      Intra object redzone:    bb
      ASan internal:           fe
      Left alloca redzone:     ca
      Right alloca redzone:    cb
    ==6160==ABORTING
    
     
  • bluehazzard

    bluehazzard - 2018-10-08

    Just for my understanding: The window gets destroyed before all CLOSE and SHUTDOWN events are processed?
    If yes: Is there no way to whait for all events to be processed and the event queue to be empty?

     
  • Teodor Petrov

    Teodor Petrov - 2018-10-11

    The problem happens because there is a Manager::Yield() in MainFrame::OnApplicationClose. This call to yield make wxWidgets execute all events in its event queue and infortunately there are events related to delayed destruction of the current window.

    If I remove the Yield call the bug goes away, but the question is what else does this break. I've tested if the APP_SHUTDOWN event is still sent and received. And I found no problems with this.

     
  • Teodor Petrov

    Teodor Petrov - 2018-10-14
    • Milestone: Undefined --> Release_xx.yy
     
  • Teodor Petrov

    Teodor Petrov - 2018-10-14

    The window is destroyed in the CodeBlocksApp::OnInit method and this needs to change.

     
  • Teodor Petrov

    Teodor Petrov - 2018-12-15
    • status: open --> fixed
    • Type: Patch --> Bug_Report
     
  • Teodor Petrov

    Teodor Petrov - 2018-12-15

    Fix committed. Lets see what else breaks with this one.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.