Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: Pecan on February 01, 2012, 07:07:49 pm

Title: Crash on CB termination svn 7737
Post by: Pecan on February 01, 2012, 07:07:49 pm
In cbproject.cpp, if the line "delete f;" occurs before the line "m_FileArray.Remove(*it);" CB crashes on termination.

If the "delete f;" follows after the "Remove", crashes disappear.

Current SVN code:
Code
if (f)
{
Manager::Get()->GetEditorManager()->Close(f->file.GetFullPath(),true);
delete f;
}
m_Files.erase(it);
m_FileArray.Remove(*it);
it = m_Files.begin();
}
Manager::Get()->GetEditorManager()->ShowNotebook();

It might be that wxArray.Remove(item&) is actually referencing the item.
Title: Re: Crash on CB termination svn 7737
Post by: thomas on February 02, 2012, 11:06:26 am
Pecan deserves the find-most-stupid-random-crash-bug-2012 award.  8)

It's exactly as you say, wxArray::Remove(T&) retrieves the index of the element to be removed by comparing every item in the array against the to-be-removed item. It's a real pain to verify that, digging through 5 indirections of wx-macro-crap, but actually, if you think about it, that's kind of obvious -- there is hardly any other way it could be.

Thus, it's dereferencing unallocated memory, which sometimes works and sometimes crashes. The delete must be after Remove.

Commit your change please?
Title: Re: Crash on CB termination svn 7737
Post by: Pecan on February 02, 2012, 02:03:48 pm
Could another team member commit this change.
Thomas ?
I only have permissions to modify my own plugins.
Title: Re: Crash on CB termination svn 7737
Post by: thomas on February 02, 2012, 02:53:03 pm
r7764
Title: Re: Crash on CB termination svn 7737
Post by: Jenna on February 05, 2012, 01:28:13 pm
I changed this code again, because the crash still occured in some cases.
I hope it's finally done, by clearing both array after closing the projectfiles.
There is no need to remove the pointers one by one, because the arrays should be empty in all cases.
See also  http://forums.codeblocks.org/index.php/topic,15901.msg107151.html#msg107151 (http://forums.codeblocks.org/index.php/topic,15901.msg107151.html#msg107151) .