From 0eb7eefcb539e75c59d8b3b5651d0cddd424596f Mon Sep 17 00:00:00 2001 From: Uleat Date: Fri, 16 Jan 2015 18:07:19 -0500 Subject: [PATCH] Fix for possible race/crash condition in ItemInst::ClearByFlags() --- common/item.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/common/item.cpp b/common/item.cpp index 044d55d3d..533a0817b 100644 --- a/common/item.cpp +++ b/common/item.cpp @@ -1710,9 +1710,17 @@ void ItemInst::ClearByFlags(byFlagSetting is_nodrop, byFlagSetting is_norent) end = m_contents.end(); for (; cur != end;) { ItemInst* inst = cur->second; - if (inst == nullptr) + if (inst == nullptr) { + cur = m_contents.erase(cur); continue; + } + const Item_Struct* item = inst->GetItem(); + if (item == nullptr) { + cur = m_contents.erase(cur); + continue; + } + del = cur; ++cur; @@ -1723,6 +1731,7 @@ void ItemInst::ClearByFlags(byFlagSetting is_nodrop, byFlagSetting is_norent) m_contents.erase(del->first); continue; } + // no 'break;' deletes 'byFlagNotSet' type - can't add at the moment because it really *breaks* the process somewhere case byFlagNotSet: if (item->NoDrop != 0) { safe_delete(inst); @@ -1740,6 +1749,7 @@ void ItemInst::ClearByFlags(byFlagSetting is_nodrop, byFlagSetting is_norent) m_contents.erase(del->first); continue; } + // no 'break;' deletes 'byFlagNotSet' type - can't add at the moment because it really *breaks* the process somewhere case byFlagNotSet: if (item->NoRent != 0) { safe_delete(inst);