From 49b30c47f7b4f995ad1315e7845d38eed25e027a Mon Sep 17 00:00:00 2001 From: LordGrey <48840279+Lord-Grey@users.noreply.github.com> Date: Sun, 22 Mar 2020 22:07:19 +0100 Subject: [PATCH] fix: Memoryleaks & Coredump, if no Grabber compiled (#724) * Fix Memoryleaks & Coredump, if no Grabber * Fix Memoryleaks & Coredump, if no Grabber --- libsrc/hyperion/ImageProcessor.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/libsrc/hyperion/ImageProcessor.cpp b/libsrc/hyperion/ImageProcessor.cpp index 4c6269be..73935938 100644 --- a/libsrc/hyperion/ImageProcessor.cpp +++ b/libsrc/hyperion/ImageProcessor.cpp @@ -69,8 +69,11 @@ void ImageProcessor::setSize(const unsigned width, const unsigned height) return; } - // Clean up the old buffer and mapping - _imageToLeds = 0; + if ( _imageToLeds != nullptr) + { + // Clean up the old buffer and mapping + delete _imageToLeds; + } // Construct a new buffer and mapping _imageToLeds = (width>0 && height>0) ? (new ImageToLedsMap(width, height, 0, 0, _ledString.leds())) : nullptr; @@ -78,17 +81,20 @@ void ImageProcessor::setSize(const unsigned width, const unsigned height) void ImageProcessor::setLedString(const LedString& ledString) { - _ledString = ledString; + if ( _imageToLeds != nullptr) + { + _ledString = ledString; - // get current width/height - const unsigned width = _imageToLeds->width(); - const unsigned height = _imageToLeds->height(); + // get current width/height + unsigned width = _imageToLeds->width(); + unsigned height = _imageToLeds->height(); - // Clean up the old buffer and mapping - _imageToLeds = 0; + // Clean up the old buffer and mapping + delete _imageToLeds; - // Construct a new buffer and mapping - _imageToLeds = new ImageToLedsMap(width, height, 0, 0, _ledString.leds()); + // Construct a new buffer and mapping + _imageToLeds = new ImageToLedsMap(width, height, 0, 0, _ledString.leds()); + } } void ImageProcessor::setBlackbarDetectDisable(bool enable)