From 210dea15de6502d56945dfd0c4114219a4ffd71a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Sun, 8 Apr 2018 14:58:02 +0100 Subject: [PATCH] Use smart pointer for SmartStatus. Fixes a memory leak. --- src/core/device.cpp | 5 ++--- src/core/device_p.h | 4 +++- src/core/smartstatus.h | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core/device.cpp b/src/core/device.cpp index 2db86df..b52177c 100644 --- a/src/core/device.cpp +++ b/src/core/device.cpp @@ -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(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. */ diff --git a/src/core/device_p.h b/src/core/device_p.h index 5ddab62..0577fe3 100644 --- a/src/core/device_p.h +++ b/src/core/device_p.h @@ -19,6 +19,8 @@ #include +#include + 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 m_SmartStatus; Device::Type m_Type; }; diff --git a/src/core/smartstatus.h b/src/core/smartstatus.h index d064b7e..88b410d 100644 --- a/src/core/smartstatus.h +++ b/src/core/smartstatus.h @@ -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;