| 453 | |
| 454 | |
| 455 | void CGenericClientListCtrl::RemoveKnownFile(CKnownFile* file) |
| 456 | { |
| 457 | // Pure pointer-value comparison — `file` may already be freed by |
| 458 | // the destruction site that fired Notify_KnownFileBeingDestroyed. |
| 459 | // We must never dereference it; we only need its value as a key |
| 460 | // to drop from m_knownfiles and m_ListItems. See |
| 461 | // MuleNotify::KnownFileBeingDestroyed in GuiEvents.cpp. |
| 462 | if (file == NULL) { |
| 463 | return; |
| 464 | } |
| 465 | |
| 466 | // Drop the cached "currently showing sources for" entry. This is |
| 467 | // #755's crash site: without this, the next ShowSources() loop |
| 468 | // at GenericClientListCtrl.cpp:355-359 walks the dangling entry |
| 469 | // and writes 1 byte into the recycled heap region via |
| 470 | // SetShowSources(file, false). |
| 471 | CKnownFileVector::iterator kf = |
| 472 | std::find(m_knownfiles.begin(), m_knownfiles.end(), file); |
| 473 | if (kf != m_knownfiles.end()) { |
| 474 | m_knownfiles.erase(kf); |
| 475 | } |
| 476 | |
| 477 | // Strip any per-row state whose m_owner matches. We have to walk |
| 478 | // the multimap once because m_ListItems is keyed by client ECID, |
| 479 | // not by file. wxListCtrl rows associated with those items are |
| 480 | // removed in the same pass via DeleteItem. |
| 481 | for (ListItems::iterator it = m_ListItems.begin(); |
| 482 | it != m_ListItems.end(); /* manual ++ */) { |
| 483 | ClientCtrlItem_Struct* item = it->second; |
| 484 | if (item && item->GetOwner() == file) { |
| 485 | // Drop the wx row first while the multimap entry is |
| 486 | // still valid, then erase the multimap entry. |
| 487 | long row = FindItem(-1, reinterpret_cast<wxUIntPtr>(item)); |
| 488 | if (row != -1) { |
| 489 | DeleteItem(row); |
| 490 | } |
| 491 | delete item; |
| 492 | m_ListItems.erase(it++); |
| 493 | } else { |
| 494 | ++it; |
| 495 | } |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | |
| 500 | /** |
no test coverage detected