Use smart pointer for SmartStatus.

Fixes a memory leak.
This commit is contained in:
Andrius Štikonas 2018-04-08 14:58:02 +01:00
parent a71be700ba
commit 210dea15de
3 changed files with 6 additions and 5 deletions

View File

@ -44,7 +44,7 @@ Device::Device(const QString& name,
d->m_TotalLogical = totalLogicalSectors;
d->m_PartitionTable = nullptr;
d->m_IconName = iconName.isEmpty() ? QStringLiteral("drive-harddisk") : iconName;
d->m_SmartStatus = type == Device::Disk_Device ? new SmartStatus(deviceNode) : nullptr;
d->m_SmartStatus = type == Device::Disk_Device ? std::make_shared<SmartStatus>(deviceNode) : nullptr;
d->m_Type = type;
}
@ -62,11 +62,10 @@ Device::Device(const Device& other)
d->m_IconName = other.d->m_IconName;
d->m_SmartStatus = nullptr;
d->m_Type = other.d->m_Type;
d->m_SmartStatus = other.d->m_SmartStatus;
if (other.d->m_PartitionTable)
d->m_PartitionTable = new PartitionTable(*other.d->m_PartitionTable);
if (other.d->m_SmartStatus)
d->m_SmartStatus = new SmartStatus(*other.d->m_SmartStatus);
}
/** Destructs a Device. */

View File

@ -19,6 +19,8 @@
#include <QString>
#include <memory>
class PartitionTable;
class SmartStatus;
@ -30,6 +32,6 @@ struct DevicePrivate
qint64 m_TotalLogical;
PartitionTable* m_PartitionTable;
QString m_IconName;
SmartStatus* m_SmartStatus;
std::shared_ptr<SmartStatus> m_SmartStatus;
Device::Type m_Type;
};

View File

@ -121,7 +121,7 @@ public:
static QString overallAssessmentToString(Overall o);
static QString selfTestStatusToString(SmartStatus::SelfTestStatus s);
protected:
private:
void setStatus(bool s)
{
m_Status = s;