mirror of
https://github.com/wled/WLED.git
synced 2025-07-13 13:56:35 +00:00
fx functions: avoid memory corruption
* PSRAM_Allocator was missing the "reallocate" method, which lead to undefined behaviour when dynamic JSON doc needed to grow/shrink * Segment::setUpLeds() quickfix for length() == 0 (should not happen, but it did happen for me once) * leds in PSRAM causes major slowdown on wrover boards - disabled.
This commit is contained in:
parent
a717238f76
commit
e4a9f115cb
@ -199,13 +199,14 @@ void Segment::setUpLeds() {
|
|||||||
#else
|
#else
|
||||||
leds = &Segment::_globalLeds[start];
|
leds = &Segment::_globalLeds[start];
|
||||||
#endif
|
#endif
|
||||||
else if (!leds) {
|
else if (leds == nullptr) {
|
||||||
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM)
|
//#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM)
|
||||||
if (psramFound())
|
//if (psramFound())
|
||||||
leds = (CRGB*)ps_malloc(sizeof(CRGB)*length());
|
// leds = (CRGB*)ps_malloc(sizeof(CRGB)*length()); // softhack007 disabled; putting leds into psram leads to horrible slowdown on WROVER boards
|
||||||
else
|
//else
|
||||||
#endif
|
//#endif
|
||||||
leds = (CRGB*)malloc(sizeof(CRGB)*length());
|
if (length() > 0) //softhack007 quickfix - avoid malloc(0) which is undefined behaviour (should not happen, but i've seen it)
|
||||||
|
leds = (CRGB*)malloc(sizeof(CRGB)*length());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,6 +151,10 @@ struct PSRAM_Allocator {
|
|||||||
if (psramFound()) return ps_malloc(size); // use PSRAM if it exists
|
if (psramFound()) return ps_malloc(size); // use PSRAM if it exists
|
||||||
else return malloc(size); // fallback
|
else return malloc(size); // fallback
|
||||||
}
|
}
|
||||||
|
void* reallocate(void* ptr, size_t new_size) {
|
||||||
|
if (psramFound()) return ps_realloc(ptr, new_size); // use PSRAM if it exists
|
||||||
|
else return realloc(ptr, new_size); // fallback
|
||||||
|
}
|
||||||
void deallocate(void* pointer) {
|
void deallocate(void* pointer) {
|
||||||
free(pointer);
|
free(pointer);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user