Skip to content

[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

Merged
merged 2 commits into from
Apr 9, 2025

Conversation

Mauller
Copy link

@Mauller Mauller commented Apr 8, 2025

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.

@Mauller Mauller self-assigned this Apr 8, 2025
@Mauller Mauller added Major Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour Stability Concerns stability of the runtime labels Apr 8, 2025
Copy link

@xezon xezon left a 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 );
Copy link

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.

Copy link
Author

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 );
Copy link

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)
Copy link

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.

@xezon xezon added Minor Severity: Minor < Major < Critical < Blocker Fix Is fixing something and removed Major Severity: Minor < Major < Critical < Blocker labels Apr 8, 2025
@xezon xezon added this to the Code foundation build up milestone Apr 8, 2025
@xezon xezon changed the title [GEN][ZH] Fix incorrect container use in iterator loops [GEN][ZH] Fix list element erasure with iterator on unrelated container in ResourceGatheringManager::findBestSupplyCenter, MilesAudioManager::killLowestPrioritySoundImmediately Apr 9, 2025
@xezon xezon merged commit 154ce66 into TheSuperHackers:main Apr 9, 2025
17 checks passed
@xezon xezon deleted the fix-incorrect-container-use branch April 9, 2025 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Is fixing something Gen Relates to Generals Minor Severity: Minor < Major < Critical < Blocker Stability Concerns stability of the runtime ZH Relates to Zero Hour
Projects
None yet
2 participants