Fix Memory leak in BlackBorderProcessor

This commit is contained in:
LordGrey
2023-12-28 18:12:47 +01:00
parent 592e61de2c
commit 0c87869339
2 changed files with 4 additions and 12 deletions

View File

@@ -24,7 +24,7 @@ namespace hyperion
Q_OBJECT Q_OBJECT
public: public:
BlackBorderProcessor(Hyperion* hyperion, QObject* parent); BlackBorderProcessor(Hyperion* hyperion, QObject* parent);
~BlackBorderProcessor() override;
/// ///
/// Return the current (detected) border /// Return the current (detected) border
/// @return The current border /// @return The current border
@@ -141,7 +141,7 @@ namespace hyperion
QString _detectionMode; QString _detectionMode;
/// The black-border detector /// The black-border detector
BlackBorderDetector* _detector; std::unique_ptr<BlackBorderDetector> _detector;
/// The current detected border /// The current detected border
BlackBorder _currentBorder; BlackBorder _currentBorder;

View File

@@ -35,12 +35,7 @@ BlackBorderProcessor::BlackBorderProcessor(Hyperion* hyperion, QObject* parent)
// listen for component state changes // listen for component state changes
connect(_hyperion, &Hyperion::compStateChangeRequest, this, &BlackBorderProcessor::handleCompStateChangeRequest); connect(_hyperion, &Hyperion::compStateChangeRequest, this, &BlackBorderProcessor::handleCompStateChangeRequest);
_detector = new BlackBorderDetector(_oldThreshold); _detector = std::make_unique<BlackBorderDetector>(_oldThreshold);
}
BlackBorderProcessor::~BlackBorderProcessor()
{
delete _detector;
} }
void BlackBorderProcessor::handleSettingsUpdate(settings::type type, const QJsonDocument& config) void BlackBorderProcessor::handleSettingsUpdate(settings::type type, const QJsonDocument& config)
@@ -66,10 +61,7 @@ void BlackBorderProcessor::handleSettingsUpdate(settings::type type, const QJson
if (fabs(_oldThreshold - newThreshold) > std::numeric_limits<double>::epsilon()) if (fabs(_oldThreshold - newThreshold) > std::numeric_limits<double>::epsilon())
{ {
_oldThreshold = newThreshold; _oldThreshold = newThreshold;
_detector = std::make_unique<BlackBorderDetector>(_oldThreshold);
delete _detector;
_detector = new BlackBorderDetector(newThreshold);
} }
Debug(Logger::getInstance("BLACKBORDER", "I"+QString::number(_hyperion->getInstanceIndex())), "Set mode to: %s", QSTRING_CSTR(_detectionMode)); Debug(Logger::getInstance("BLACKBORDER", "I"+QString::number(_hyperion->getInstanceIndex())), "Set mode to: %s", QSTRING_CSTR(_detectionMode));