Fix for possible race/crash condition in ItemInst::ClearByFlags()

This commit is contained in:
Uleat 2015-01-16 18:07:19 -05:00
parent 4978999d78
commit 0eb7eefcb5

View File

@ -1710,9 +1710,17 @@ void ItemInst::ClearByFlags(byFlagSetting is_nodrop, byFlagSetting is_norent)
end = m_contents.end(); end = m_contents.end();
for (; cur != end;) { for (; cur != end;) {
ItemInst* inst = cur->second; ItemInst* inst = cur->second;
if (inst == nullptr) if (inst == nullptr) {
cur = m_contents.erase(cur);
continue; continue;
}
const Item_Struct* item = inst->GetItem(); const Item_Struct* item = inst->GetItem();
if (item == nullptr) {
cur = m_contents.erase(cur);
continue;
}
del = cur; del = cur;
++cur; ++cur;
@ -1723,6 +1731,7 @@ void ItemInst::ClearByFlags(byFlagSetting is_nodrop, byFlagSetting is_norent)
m_contents.erase(del->first); m_contents.erase(del->first);
continue; continue;
} }
// no 'break;' deletes 'byFlagNotSet' type - can't add at the moment because it really *breaks* the process somewhere
case byFlagNotSet: case byFlagNotSet:
if (item->NoDrop != 0) { if (item->NoDrop != 0) {
safe_delete(inst); safe_delete(inst);
@ -1740,6 +1749,7 @@ void ItemInst::ClearByFlags(byFlagSetting is_nodrop, byFlagSetting is_norent)
m_contents.erase(del->first); m_contents.erase(del->first);
continue; continue;
} }
// no 'break;' deletes 'byFlagNotSet' type - can't add at the moment because it really *breaks* the process somewhere
case byFlagNotSet: case byFlagNotSet:
if (item->NoRent != 0) { if (item->NoRent != 0) {
safe_delete(inst); safe_delete(inst);