Skip to content

Commit 01c187f

Browse files
committed
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.
1 parent f699a56 commit 01c187f

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

wled00/FX.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
bool canUseSerial(void); // WLEDMM implemented in wled_serial.cpp
3535
void strip_wait_until_idle(String whoCalledMe); // WLEDMM implemented in FX_fcn.cpp
36+
bool strip_uses_global_leds(void); // WLEDMM implemented in FX_fcn.cpp
3637

3738
#define FASTLED_INTERNAL //remove annoying pragma messages
3839
#define USE_GET_MILLISECOND_TIMER
@@ -516,7 +517,11 @@ typedef struct Segment {
516517
if (name) Serial.printf(" name=%s (%p)", name, name);
517518
if (data) Serial.printf(" dataLen=%d (%p)", (int)_dataLen, data);
518519
if (ledsrgb) Serial.printf(" [%sledsrgb %u bytes]", Segment::_globalLeds ? "global ":"",length()*sizeof(CRGB));
520+
if (strip_uses_global_leds() == true) Serial.println((Segment::_globalLeds != nullptr) ? F(" using global buffer.") : F(", using global buffer but Segment::_globalLeds is NULL!!"));
519521
Serial.println();
522+
#ifdef ARDUINO_ARCH_ESP32
523+
Serial.flush();
524+
#endif
520525
}
521526
#endif
522527

@@ -525,7 +530,7 @@ typedef struct Segment {
525530
strip_wait_until_idle("~Segment()");
526531
#endif
527532

528-
if (!Segment::_globalLeds && (ledsrgb != nullptr)) {free(ledsrgb); ledsrgb = nullptr;}
533+
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)
529534
if (name) { delete[] name; name = nullptr; }
530535
if (_t) { transitional = false; delete _t; _t = nullptr; }
531536
deallocateData();

wled00/FX_fcn.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ void strip_wait_until_idle(String whoCalledMe) {
8282
}
8383
#endif
8484
}
85-
85+
// WLEDMM another helper for segment class
86+
bool strip_uses_global_leds(void) {
87+
return strip.useLedsArray;
88+
}
8689

8790
///////////////////////////////////////////////////////////////////////////////
8891
// Segment class implementation

0 commit comments

Comments
 (0)