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

Crash on CB termination svn 7737

(1/1)

Pecan:
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();

--- End code ---

It might be that wxArray.Remove(item&) is actually referencing the item.

thomas:
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?

Pecan:
Could another team member commit this change.
Thomas ?
I only have permissions to modify my own plugins.

thomas:
r7764

Jenna:
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 .

Navigation

[0] Message Index

Go to full version