From dda5ddd3e63e33be5b9e3efa6b23c326ecbcecbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Mon, 9 Apr 2018 16:16:02 +0100 Subject: [PATCH] Fix more memory leaks in SmartDiskInformation. --- src/core/smartdiskinformation.cpp | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/core/smartdiskinformation.cpp b/src/core/smartdiskinformation.cpp index 1c42d20..85a5dbb 100644 --- a/src/core/smartdiskinformation.cpp +++ b/src/core/smartdiskinformation.cpp @@ -18,6 +18,8 @@ #include "core/smartdiskinformation.h" #include "core/smartattributeparseddata.h" +#include + static quint64 u64log2(quint64 n); /** Creates a new SmartDiskInformationObject */ @@ -41,11 +43,8 @@ SmartDiskInformation::SmartDiskInformation() : /** Update the number of bad sectors based on reallocated sector count and current pending sector attributes data */ void SmartDiskInformation::updateBadSectors() { - SmartAttributeParsedData *reallocatedSectorCt; - reallocatedSectorCt = findAttribute(5); - - SmartAttributeParsedData *currentPendingSector; - currentPendingSector = findAttribute(197); + std::unique_ptr reallocatedSectorCt(findAttribute(5)); + std::unique_ptr currentPendingSector(findAttribute(197)); if (!reallocatedSectorCt && !currentPendingSector) m_BadSectors = 0; @@ -97,13 +96,9 @@ void SmartDiskInformation::updateOverall() */ bool SmartDiskInformation::updateTemperature() { - SmartAttributeParsedData *temperatureCelsius; - SmartAttributeParsedData *temperatureCelsius2; - SmartAttributeParsedData *airflowTemperatureCelsius; - - temperatureCelsius = findAttribute(231); - temperatureCelsius2 = findAttribute(194); - airflowTemperatureCelsius = findAttribute(190); + std::unique_ptr temperatureCelsius(findAttribute(231)); + std::unique_ptr temperatureCelsius2(findAttribute(194)); + std::unique_ptr airflowTemperatureCelsius(findAttribute(190)); if (temperatureCelsius != nullptr && temperatureCelsius->prettyUnit() == SmartAttributeUnit::Milikelvin) { @@ -127,11 +122,8 @@ bool SmartDiskInformation::updateTemperature() */ bool SmartDiskInformation::updatePowerOn() { - SmartAttributeParsedData *powerOnHours; - SmartAttributeParsedData *powerOnSeconds; - - powerOnHours = findAttribute(9); - powerOnSeconds = findAttribute(233); + std::unique_ptr powerOnHours(findAttribute(9)); + std::unique_ptr powerOnSeconds(findAttribute(233)); if (powerOnHours != nullptr && powerOnHours->prettyUnit() == SmartAttributeUnit::Miliseconds) { @@ -150,9 +142,7 @@ bool SmartDiskInformation::updatePowerOn() */ bool SmartDiskInformation::updatePowerCycle() { - SmartAttributeParsedData *powerCycleCount; - - powerCycleCount = findAttribute(12); + std::unique_ptr powerCycleCount(findAttribute(12)); if (powerCycleCount != nullptr && powerCycleCount->prettyUnit() == SmartAttributeUnit::None) {