Fix memory leaks from DeckLoader usage (#5665)

* add comment

* stack allocate DeckLoader for loading tags

* deckModel now takes ownership of DeckLoader

* fix remaining

* add comment
This commit is contained in:
RickyRister 2025-03-02 15:57:30 -08:00 committed by GitHub
parent 87c5d07807
commit e1964f21de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 33 additions and 8 deletions

View file

@ -18,6 +18,7 @@ DeckListModel::DeckListModel(QObject *parent)
: QAbstractItemModel(parent), lastKnownColumn(1), lastKnownOrder(Qt::AscendingOrder)
{
deckList = new DeckLoader;
deckList->setParent(this);
connect(deckList, &DeckLoader::deckLoaded, this, &DeckListModel::rebuildTree);
connect(deckList, &DeckLoader::deckHashChanged, this, &DeckListModel::deckHashChanged);
root = new InnerDecklistNode;
@ -26,7 +27,6 @@ DeckListModel::DeckListModel(QObject *parent)
DeckListModel::~DeckListModel()
{
delete root;
delete deckList;
}
void DeckListModel::rebuildTree()
@ -470,10 +470,14 @@ void DeckListModel::cleanList()
setDeckList(new DeckLoader);
}
/**
* @param _deck The deck. Takes ownership of the object
*/
void DeckListModel::setDeckList(DeckLoader *_deck)
{
delete deckList;
deckList->deleteLater();
deckList = _deck;
deckList->setParent(this);
connect(deckList, &DeckLoader::deckLoaded, this, &DeckListModel::rebuildTree);
connect(deckList, &DeckLoader::deckHashChanged, this, &DeckListModel::deckHashChanged);
rebuildTree();