mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-09 03:23:24 -08:00
[CardDB] Clear CardInfo relations before deferred deletion (#7615)
removeCard() and swapInDatabaseData() schedule CardRelation deletion with deleteLater(), but the owning CardInfo could outlive them through an external shared pointer and kept returning the freed pointers from getAllRelatedCards(). Add CardInfo::clearDirectRelations() and call it after scheduling deletion so the UI can no longer dereference dangling relations. Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
6e770eb7b2
commit
4028606bd9
4 changed files with 49 additions and 0 deletions
|
|
@ -168,6 +168,10 @@ void CardDatabase::removeCard(const CardInfoPtr &card)
|
|||
cardRelation->deleteLater();
|
||||
}
|
||||
|
||||
// The relations are only scheduled for deletion; the CardInfo may outlive
|
||||
// them through an external shared pointer, so drop the raw pointers now.
|
||||
card->clearDirectRelations();
|
||||
|
||||
QMutexLocker locker(removeCardMutex);
|
||||
cards.remove(card->getName());
|
||||
simpleNameCards.remove(card->getSimpleName());
|
||||
|
|
@ -271,6 +275,9 @@ void CardDatabase::swapInDatabaseData(CardDatabaseData data)
|
|||
for (auto *rel : card->getReverseRelatedCards2Me()) {
|
||||
rel->deleteLater();
|
||||
}
|
||||
// Replacement cards take over the database; old CardInfo objects may
|
||||
// still be referenced by the UI, so clear their dangling relations.
|
||||
card->clearDirectRelations();
|
||||
}
|
||||
|
||||
cards = std::move(data.cards);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue