Fix more memory leaks in SmartDiskInformation.

This commit is contained in:
Andrius Štikonas 2018-04-09 16:16:02 +01:00
parent a9a637454a
commit dda5ddd3e6
1 changed files with 10 additions and 20 deletions

View File

@ -18,6 +18,8 @@
#include "core/smartdiskinformation.h" #include "core/smartdiskinformation.h"
#include "core/smartattributeparseddata.h" #include "core/smartattributeparseddata.h"
#include <memory>
static quint64 u64log2(quint64 n); static quint64 u64log2(quint64 n);
/** Creates a new SmartDiskInformationObject */ /** 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 */ /** Update the number of bad sectors based on reallocated sector count and current pending sector attributes data */
void SmartDiskInformation::updateBadSectors() void SmartDiskInformation::updateBadSectors()
{ {
SmartAttributeParsedData *reallocatedSectorCt; std::unique_ptr<SmartAttributeParsedData> reallocatedSectorCt(findAttribute(5));
reallocatedSectorCt = findAttribute(5); std::unique_ptr<SmartAttributeParsedData> currentPendingSector(findAttribute(197));
SmartAttributeParsedData *currentPendingSector;
currentPendingSector = findAttribute(197);
if (!reallocatedSectorCt && !currentPendingSector) if (!reallocatedSectorCt && !currentPendingSector)
m_BadSectors = 0; m_BadSectors = 0;
@ -97,13 +96,9 @@ void SmartDiskInformation::updateOverall()
*/ */
bool SmartDiskInformation::updateTemperature() bool SmartDiskInformation::updateTemperature()
{ {
SmartAttributeParsedData *temperatureCelsius; std::unique_ptr<SmartAttributeParsedData> temperatureCelsius(findAttribute(231));
SmartAttributeParsedData *temperatureCelsius2; std::unique_ptr<SmartAttributeParsedData> temperatureCelsius2(findAttribute(194));
SmartAttributeParsedData *airflowTemperatureCelsius; std::unique_ptr<SmartAttributeParsedData> airflowTemperatureCelsius(findAttribute(190));
temperatureCelsius = findAttribute(231);
temperatureCelsius2 = findAttribute(194);
airflowTemperatureCelsius = findAttribute(190);
if (temperatureCelsius != nullptr if (temperatureCelsius != nullptr
&& temperatureCelsius->prettyUnit() == SmartAttributeUnit::Milikelvin) { && temperatureCelsius->prettyUnit() == SmartAttributeUnit::Milikelvin) {
@ -127,11 +122,8 @@ bool SmartDiskInformation::updateTemperature()
*/ */
bool SmartDiskInformation::updatePowerOn() bool SmartDiskInformation::updatePowerOn()
{ {
SmartAttributeParsedData *powerOnHours; std::unique_ptr<SmartAttributeParsedData> powerOnHours(findAttribute(9));
SmartAttributeParsedData *powerOnSeconds; std::unique_ptr<SmartAttributeParsedData> powerOnSeconds(findAttribute(233));
powerOnHours = findAttribute(9);
powerOnSeconds = findAttribute(233);
if (powerOnHours != nullptr if (powerOnHours != nullptr
&& powerOnHours->prettyUnit() == SmartAttributeUnit::Miliseconds) { && powerOnHours->prettyUnit() == SmartAttributeUnit::Miliseconds) {
@ -150,9 +142,7 @@ bool SmartDiskInformation::updatePowerOn()
*/ */
bool SmartDiskInformation::updatePowerCycle() bool SmartDiskInformation::updatePowerCycle()
{ {
SmartAttributeParsedData *powerCycleCount; std::unique_ptr<SmartAttributeParsedData> powerCycleCount(findAttribute(12));
powerCycleCount = findAttribute(12);
if (powerCycleCount != nullptr if (powerCycleCount != nullptr
&& powerCycleCount->prettyUnit() == SmartAttributeUnit::None) { && powerCycleCount->prettyUnit() == SmartAttributeUnit::None) {