From 01c187f8aa45254e7b15fea1dcb1e4ce172e3475 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Tue, 2 Jan 2024 15:52:00 +0100 Subject: [PATCH] bugfix for #104 this avoids heap corruption, by double-checking that "use global leds" is not configured, before trying to free ledsrgb[]. It is still a mystery why Segment::_globalLeds == nullptr. --- wled00/FX.h | 7 ++++++- wled00/FX_fcn.cpp | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/wled00/FX.h b/wled00/FX.h index fa7a3ef4..1cba9000 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -33,6 +33,7 @@ bool canUseSerial(void); // WLEDMM implemented in wled_serial.cpp void strip_wait_until_idle(String whoCalledMe); // WLEDMM implemented in FX_fcn.cpp +bool strip_uses_global_leds(void); // WLEDMM implemented in FX_fcn.cpp #define FASTLED_INTERNAL //remove annoying pragma messages #define USE_GET_MILLISECOND_TIMER @@ -516,7 +517,11 @@ typedef struct Segment { if (name) Serial.printf(" name=%s (%p)", name, name); if (data) Serial.printf(" dataLen=%d (%p)", (int)_dataLen, data); if (ledsrgb) Serial.printf(" [%sledsrgb %u bytes]", Segment::_globalLeds ? "global ":"",length()*sizeof(CRGB)); + if (strip_uses_global_leds() == true) Serial.println((Segment::_globalLeds != nullptr) ? F(" using global buffer.") : F(", using global buffer but Segment::_globalLeds is NULL!!")); Serial.println(); + #ifdef ARDUINO_ARCH_ESP32 + Serial.flush(); + #endif } #endif @@ -525,7 +530,7 @@ typedef struct Segment { strip_wait_until_idle("~Segment()"); #endif - if (!Segment::_globalLeds && (ledsrgb != nullptr)) {free(ledsrgb); ledsrgb = nullptr;} + if ((Segment::_globalLeds == nullptr) && !strip_uses_global_leds() && (ledsrgb != nullptr)) {free(ledsrgb); ledsrgb = nullptr;} // WLEDMM we need "!strip_uses_global_leds()" to avoid crashes (#104) if (name) { delete[] name; name = nullptr; } if (_t) { transitional = false; delete _t; _t = nullptr; } deallocateData(); diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 72e302dc..c62ae60d 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -82,7 +82,10 @@ void strip_wait_until_idle(String whoCalledMe) { } #endif } - +// WLEDMM another helper for segment class +bool strip_uses_global_leds(void) { + return strip.useLedsArray; +} /////////////////////////////////////////////////////////////////////////////// // Segment class implementation