[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:
BruebachL 2026-10-24 10:28:24 +02:00 • committed by GitHub
parent 6e770eb7b2
commit 4028606bd9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 49 additions and 0 deletions

View file

@ -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);