From fbc29b6a0626f2ce8521dc74e3171b634d68e9e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 30 Mar 2014 20:11:05 +0200 Subject: Fix many memory leaks. --- logic/lists/InstanceList.cpp | 14 +++++++++----- logic/lists/InstanceList.h | 5 +++-- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'logic/lists') diff --git a/logic/lists/InstanceList.cpp b/logic/lists/InstanceList.cpp index 34e6d87b..1ff0d2ec 100644 --- a/logic/lists/InstanceList.cpp +++ b/logic/lists/InstanceList.cpp @@ -90,6 +90,10 @@ QVariant InstanceList::data(const QModelIndex &index, int role) const QVariant v = qVariantFromValue((void *)pdata); return v; } + case InstanceIDRole: + { + return pdata->id(); + } case Qt::DisplayRole: { return pdata->name(); @@ -378,7 +382,7 @@ void InstanceList::loadFTBInstances(QMap &groupMap, if (!QFileInfo(PathCombine(record.instanceDir, "instance.cfg")).exists()) { QLOG_INFO() << "Converting " << record.name << " as new."; - BaseInstance *instPtr = NULL; + InstancePtr instPtr; auto &factory = InstanceFactory::get(); auto version = MMC->minecraftlist()->findVersion(record.mcVersion); if (!version) @@ -406,7 +410,7 @@ void InstanceList::loadFTBInstances(QMap &groupMap, else { QLOG_INFO() << "Loading existing " << record.name; - BaseInstance *instPtr = NULL; + InstancePtr instPtr; auto error = InstanceFactory::get().loadInstance(instPtr, record.instanceDir); if (!instPtr || error != InstanceFactory::NoLoadError) continue; @@ -439,11 +443,11 @@ InstanceList::InstListError InstanceList::loadList() if (!QFileInfo(PathCombine(subDir, "instance.cfg")).exists()) continue; QLOG_INFO() << "Loading MultiMC instance from " << subDir; - BaseInstance *instPtr = NULL; + InstancePtr instPtr; auto error = InstanceFactory::get().loadInstance(instPtr, subDir); if(!continueProcessInstance(instPtr, error, subDir, groupMap)) continue; - tempList.append(InstancePtr(instPtr)); + tempList.append(instPtr); } } @@ -536,7 +540,7 @@ int InstanceList::getInstIndex(BaseInstance *inst) const return -1; } -bool InstanceList::continueProcessInstance(BaseInstance *instPtr, const int error, +bool InstanceList::continueProcessInstance(InstancePtr instPtr, const int error, const QDir &dir, QMap &groupMap) { if (error != InstanceFactory::NoLoadError && error != InstanceFactory::NotAnInstance) diff --git a/logic/lists/InstanceList.h b/logic/lists/InstanceList.h index ebe3e051..f0bbb7ec 100644 --- a/logic/lists/InstanceList.h +++ b/logic/lists/InstanceList.h @@ -62,7 +62,8 @@ public: enum AdditionalRoles { - InstancePointerRole = 0x34B1CB48 ///< Return pointer to real instance + InstancePointerRole = 0x34B1CB48, ///< Return pointer to real instance + InstanceIDRole = 0x34B1CB49 ///< Return id if the instance }; /*! * \brief Error codes returned by functions in the InstanceList class. @@ -132,7 +133,7 @@ slots: private: int getInstIndex(BaseInstance *inst) const; - bool continueProcessInstance(BaseInstance *instPtr, const int error, const QDir &dir, + bool continueProcessInstance(InstancePtr instPtr, const int error, const QDir &dir, QMap &groupMap); protected: -- cgit v1.2.3