fix(model): avoid use after free in CM2Model::DetachAllChildrenById

This commit is contained in:
fallenoak 2025-10-27 23:20:07 -05:00
parent aa7e548102
commit 5e9b2316dc
No known key found for this signature in database
GPG Key ID: 7628F8E61AEA070D

View File

@ -778,7 +778,13 @@ void CM2Model::CancelDeferredSequences(uint32_t boneIndex, bool a3) {
} }
void CM2Model::DetachAllChildrenById(uint32_t id) { void CM2Model::DetachAllChildrenById(uint32_t id) {
for (auto model = this->m_attachList; model; model = model->m_attachNext) { // Hang on to attachNext in case model is freed during detach
CM2Model* attachNext = nullptr;
// Detach any model matching provided attach ID
for (auto model = this->m_attachList; model; model = attachNext) {
attachNext = model->m_attachNext;
if (model->m_attachId == id) { if (model->m_attachId == id) {
model->DetachFromParent(); model->DetachFromParent();
} }