-
Notifications
You must be signed in to change notification settings - Fork 74
[GEN][ZH] Fix list element erasure with iterator on unrelated container in ResourceGatheringManager::findBestSupplyCenter, MilesAudioManager::killLowestPrioritySoundImmediately #631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes look correct.
releasePlayingAudio( playing ); | ||
m_playing3DSounds.erase( it ); | ||
m_playingSounds.erase( it ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am 99% sure that this just worked with no bugs with stlport's implementation.
iterator erase(iterator __position) {
_List_node_base* __next_node = __position._M_node->_M_next; // accesses next node
_List_node_base* __prev_node = __position._M_node->_M_prev; // accesses prev node
_Node* __n = (_Node*) __position._M_node; // accesses current node
__prev_node->_M_next = __next_node; // writes prev node
__next_node->_M_prev = __prev_node; // writes next node
_Destroy(&__n->_M_data); // calls destructor with the same type (PlayingAudio*)
this->_M_node.deallocate(__n, 1); // calls deallocate on default allocator for std::list
return iterator((_Node*)__next_node); // return local
}
Same with m_supplyCenters.erase( iterator )
So these were no runtime issues in the retail game.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is funny that it essentially looks like it does not care what container it is called on, just that erase is called with an iterator.
@@ -213,7 +213,7 @@ Object *ResourceGatheringManager::findBestSupplyCenter( Object *queryObject ) | |||
if( dock ) | |||
{ | |||
static const NameKeyType key_centerUpdate = NAMEKEY("SupplyCenterDockUpdate"); | |||
SupplyWarehouseDockUpdate *centerModule = (SupplyWarehouseDockUpdate*)dock->findUpdateModule( key_centerUpdate ); | |||
SupplyCenterDockUpdate *centerModule = (SupplyCenterDockUpdate*)dock->findUpdateModule( key_centerUpdate ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This certainly was no runtime bug, because this pointer is just tested for null.
@@ -146,7 +146,7 @@ void SubsystemInterfaceList::addSubsystem(SubsystemInterface* sys) | |||
void SubsystemInterfaceList::removeSubsystem(SubsystemInterface* sys) | |||
{ | |||
#ifdef DUMP_PERF_STATS | |||
for (SubsystemList::iterator it = m_allSubsystems.begin(); it != m_subsystems.end(); ++it) | |||
for (SubsystemList::iterator it = m_allSubsystems.begin(); it != m_allSubsystems.end(); ++it) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a debug bug fix. No concern for retail game.
Within some iterator use, likely due to copy and paste errors, there are iterators being used on the wrong container.
In the short term this can cause memory leaks as the required data is never freed from the container.
This can also cause unexpected behaviour as the container is growing with data that should have been removed.
There is also a bug fix for a cast that was setting the wrong type on a pointer, this does not seem to affect runtime but could be an issue in the future.