Author Topic: Crash on CB termination svn 7737  (Read 6494 times)

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Crash on CB termination svn 7737
« 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.
« Last Edit: February 01, 2012, 07:10:02 pm by Pecan »

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Crash on CB termination svn 7737
« Reply #1 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?
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Crash on CB termination svn 7737
« Reply #2 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.
« Last Edit: February 02, 2012, 02:21:42 pm by Pecan »

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Crash on CB termination svn 7737
« Reply #3 on: February 02, 2012, 02:53:03 pm »
r7764
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Crash on CB termination svn 7737
« Reply #4 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 .