Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

Segmentation fault in nativeparser.cpp

<< < (2/4) > >>

christobal:

--- Quote from: jarod42 on February 21, 2013, 04:42:26 pm ---I assume that DeleteParser modify m_ParserList, so the iterator 'it' is no longer valid.

Moving

--- Code: ---wxString prj = (it->first ? it->first->GetTitle() : _T("*NONE*"));
--- End code ---
just before

--- Code: ---if (DeleteParser(it->first))
--- End code ---
should fix the issue.

--- End quote ---

It does. CC seems to work as well for all opened projects.

@ollydbg: using GDB 7.2

ollydbg:

--- Quote from: jarod42 on February 21, 2013, 04:42:26 pm ---I assume that DeleteParser modify m_ParserList, so the iterator 'it' is no longer valid.

Moving

--- Code: ---wxString prj = (it->first ? it->first->GetTitle() : _T("*NONE*"));
--- End code ---
just before

--- Code: ---if (DeleteParser(it->first))
--- End code ---
should fix the issue.


--- End quote ---
You are right, I just review the logic of DeleteParser(), look below:

--- Code: ---bool NativeParser::DeleteParser(cbProject* project)
{
    wxString prj = (project ? project->GetTitle() : _T("*NONE*"));

    ParserList::iterator it = m_ParserList.begin();
    if (!m_ParserPerWorkspace)
    {
        for (; it != m_ParserList.end(); ++it)
        {
            if (it->first == project)
                break;
        }
    }

    if (it == m_ParserList.end())
    {
        CCLogger::Get()->DebugLog(F(_T("NativeParser::DeleteParser(): Parser does not exist for delete '%s'!"), prj.wx_str()));
        return false;
    }

    bool removeProjectFromParser = false;
    if (m_ParserPerWorkspace)
        removeProjectFromParser = RemoveProjectFromParser(project);

    if (m_ParsedProjects.empty())
    {
        if (it->second == m_Parser)
          SetParser(m_TempParser); // Also updates class browser

        wxString log(F(_("NativeParser::DeleteParser(): Deleting parser for project '%s'!"), prj.wx_str()));
        CCLogger::Get()->Log(log);
        CCLogger::Get()->DebugLog(log);

        delete it->second;
        m_ParserList.erase(it);

        return true;
    }

    if (removeProjectFromParser)
        return true;

    CCLogger::Get()->DebugLog(_T("NativeParser::DeleteParser(): Deleting parser failed!"));
    return false;
}

--- End code ---

Here

--- Code: ---        m_ParserList.erase(it);

--- End code ---
The element is removed.
But return from the function.

--- Code: ---it->first

--- End code ---
The constant iterator is reused.

I'm going to fix it by your suggestion. Thanks.


--- Quote from: christobal on February 22, 2013, 08:26:55 am ---It does. CC seems to work as well for all opened projects.

--- End quote ---
Thanks for the test.

--- Quote ---@ollydbg: using GDB 7.2

--- End quote ---
Thanks, but I see that longer bt report are some redundant lines like:

--- Quote ---#13 705C7B74   wxEvtHandler::ProcessEvent(wxEvent&) () (D:\codeblocks\source\src\devel\wxmsw28u_gcc_cb.dll:??)
#14 705C7B10   wxEvtHandler::ProcessEvent(wxEvent&) () (D:\codeblocks\source\src\devel\wxmsw28u_gcc_cb.dll:??)
#15 705C7B10   wxEvtHandler::ProcessEvent(wxEvent&) () (D:\codeblocks\source\src\devel\wxmsw28u_gcc_cb.dll:??)
#16 705C7B10   wxEvtHandler::ProcessEvent(wxEvent&) () (D:\codeblocks\source\src\devel\wxmsw28u_gcc_cb.dll:??)
...

--- End quote ---
Newer GDB(I'm using GDB CVS head) just stop unwinding in this cases. :)

ollydbg:
Fixed in rev 8856. Thanks for you contribution.

christobal:
Thanks for fixing.

Unfortunally, I found another one in nativeparser.cpp...

This time it happens if you open a project and *immediately* close it. The problem occures in NativeParser::OnParserStart, which seems to recceive a cbProject pointer to a project that has already been deleted (project->GetTitle refers to 0xfeeefeee).

The Backtrace (C::B Rev 8900) is:


--- Code: ---#0 00000000 0xfeeefeee in ??() (??:??)
#1 65ECCBD3 NativeParser::OnParserStart(this=0x32bd5b0, event=...) (D:\projekte\codeblocks\source2\src\plugins\codecompletion\nativeparser.cpp:2458)
#2 705C7670 wxEvtHandler::ProcessEventIfMatches(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) () (D:\projekte\codeblocks\source2\src\devel\wxmsw28u_gcc_cb.dll:??)
#3 705C7A96 wxEvtHandler::SearchDynamicEventTable(wxEvent&) () (D:\projekte\codeblocks\source2\src\devel\wxmsw28u_gcc_cb.dll:??)
#4 705C7B4B wxEvtHandler::ProcessEvent(wxEvent&) () (D:\projekte\codeblocks\source2\src\devel\wxmsw28u_gcc_cb.dll:??)
#5 65EF4C49 Parser::ProcessParserEvent(this=0x11503218, state=ParserCommon::ptCreateParser, id=1391, info=...) (D:\projekte\codeblocks\source2\src\plugins\codecompletion\parser\parser.cpp:1178)
#6 65EF3449 Parser::OnBatchTimer(this=0x11503218, event=...) (D:\projekte\codeblocks\source2\src\plugins\codecompletion\parser\parser.cpp:1078)
#7 705C7670 wxEvtHandler::ProcessEventIfMatches(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) () (D:\projekte\codeblocks\source2\src\devel\wxmsw28u_gcc_cb.dll:??)
#8 705C7A96 wxEvtHandler::SearchDynamicEventTable(wxEvent&) () (D:\projekte\codeblocks\source2\src\devel\wxmsw28u_gcc_cb.dll:??)
#9 705C7B4B wxEvtHandler::ProcessEvent(wxEvent&) () (D:\projekte\codeblocks\source2\src\devel\wxmsw28u_gcc_cb.dll:??)
#10 706D70ED wxTimerBase::Notify() () (D:\projekte\codeblocks\source2\src\devel\wxmsw28u_gcc_cb.dll:??)
#11 70607BDC wxTimerWndProc() (D:\projekte\codeblocks\source2\src\devel\wxmsw28u_gcc_cb.dll:??)
#12 75CC6238 USER32!IsDialogMessageW() (C:\Windows\syswow64\user32.dll:??)
#13 00000000 0x000309a8 in ??() (??:??)
#14 75CC68EA USER32!AllowForegroundActivation() (C:\Windows\syswow64\user32.dll:??)
#15 70607B64 wxProcessTimer(wxTimer&) () (D:\projekte\codeblocks\source2\src\devel\wxmsw28u_gcc_cb.dll:??)
#16 75CC7D31 USER32!GetMessageExtraInfo() (C:\Windows\syswow64\user32.dll:??)
#17 00000000 0x00000000 in ??() (??:??)

--- End code ---



ollydbg:

--- Quote from: christobal on March 07, 2013, 08:30:35 am ---Thanks for fixing.

Unfortunally, I found another one in nativeparser.cpp...

This time it happens if you open a project and *immediately* close it. The problem occures in NativeParser::OnParserStart, which seems to recceive a cbProject pointer to a project that has already been deleted (project->GetTitle refers to 0xfeeefeee).

The Backtrace (C::B Rev 8900) is:


--- End quote ---
Hi, many thanks for the bug report. I'm currently under heavy work load this week, so I will look into it next week.
The simple logic is: In the NativeParser, there is a Map to hold the database.

--- Code: ---cbProject*  -> Parser*
--- End code ---
Each Parser is associated with one cbProject. (In another mode, if we use one parser for the whole workspaces, then there is only one parser for all the cbProjects in the workspaces)



Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version