prevent races on leds buffer (looptask vs. async_tcp)
I still see strange crashes in setPixelColor/GetpixelColor, which ssem to come from race conditions between async_tcp (change presets) and looptask (strip.service). To make the situation better, its important that any global pointers are reset to NULL immediately after free().
This commit is contained in:
parent
7de7ef8e8c
commit
d48a96599f
@ -487,7 +487,7 @@ typedef struct Segment {
|
||||
//if (leds) Serial.printf(" [%u]", length()*sizeof(CRGB));
|
||||
//Serial.println();
|
||||
//#endif
|
||||
if (!Segment::_globalLeds && leds) free(leds);
|
||||
if (!Segment::_globalLeds && leds) { free(leds); leds = nullptr;} // reset to nullptr, to avoid race conditions
|
||||
if (name) delete[] name;
|
||||
if (_t) delete _t;
|
||||
deallocateData();
|
||||
@ -710,7 +710,7 @@ class WS2812FX { // 96 bytes
|
||||
panel.clear();
|
||||
#endif
|
||||
customPalettes.clear();
|
||||
if (useLedsArray && Segment::_globalLeds) free(Segment::_globalLeds);
|
||||
if (useLedsArray && Segment::_globalLeds) {free(Segment::_globalLeds); Segment::_globalLeds = nullptr;} // reset to nullptr, to avoid race conditions
|
||||
}
|
||||
|
||||
static WS2812FX* getInstance(void) { return instance; }
|
||||
|
@ -97,11 +97,11 @@ Segment::Segment(const Segment &orig) {
|
||||
Segment::Segment(Segment &&orig) noexcept {
|
||||
//DEBUG_PRINTLN(F("-- Move segment constructor --"));
|
||||
memcpy((void*)this, (void*)&orig, sizeof(Segment));
|
||||
orig.leds = nullptr;
|
||||
orig.name = nullptr;
|
||||
orig.data = nullptr;
|
||||
orig._dataLen = 0;
|
||||
orig._t = nullptr;
|
||||
orig.leds = nullptr;
|
||||
}
|
||||
|
||||
// copy assignment
|
||||
@ -111,7 +111,7 @@ Segment& Segment::operator= (const Segment &orig) {
|
||||
// clean destination
|
||||
if (name) delete[] name;
|
||||
if (_t) delete _t;
|
||||
if (leds && !Segment::_globalLeds) free(leds);
|
||||
if (leds && !Segment::_globalLeds) {free(leds); leds=nullptr;}
|
||||
deallocateData();
|
||||
// copy source
|
||||
memcpy((void*)this, (void*)&orig, sizeof(Segment));
|
||||
@ -137,7 +137,7 @@ Segment& Segment::operator= (Segment &&orig) noexcept {
|
||||
if (name) delete[] name; // free old name
|
||||
deallocateData(); // free old runtime data
|
||||
if (_t) delete _t;
|
||||
if (leds && !Segment::_globalLeds) free(leds);
|
||||
if (leds && !Segment::_globalLeds) {free(leds); leds=nullptr;}
|
||||
memcpy((void*)this, (void*)&orig, sizeof(Segment));
|
||||
orig.name = nullptr;
|
||||
orig.data = nullptr;
|
||||
@ -1078,7 +1078,7 @@ void WS2812FX::finalizeInit(void)
|
||||
//else
|
||||
//#endif
|
||||
Segment::_globalLeds = (CRGB*) malloc(arrSize);
|
||||
memset(Segment::_globalLeds, 0, arrSize);
|
||||
if (Segment::_globalLeds && (arrSize > 0)) memset(Segment::_globalLeds, 0, arrSize);
|
||||
}
|
||||
|
||||
//segments are created in makeAutoSegments();
|
||||
|
Loading…
Reference in New Issue
Block a user