Fix re-init segment data leak (fixes #2535 ) (#2536)

This commit is contained in:
Christian Schwinne 2022-02-09 08:43:35 +01:00 committed by GitHub
parent f9bce54104
commit 00b0193a43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 8 deletions

View File

@ -81,7 +81,6 @@
#define SEGLEN _virtualSegmentLength
#define SEGACT SEGMENT.stop
#define SPEED_FORMULA_L 5U + (50U*(255U - SEGMENT.speed))/SEGLEN
#define RESET_RUNTIME memset(_segment_runtimes, 0, sizeof(_segment_runtimes))
// some common colors
#define RED (uint32_t)0xFF0000
@ -409,8 +408,9 @@ class WS2812FX {
* Flags that before the next effect is calculated,
* the internal segment state should be reset.
* Call resetIfRequired before calling the next effect function.
* Safe to call from interrupts and network requests.
*/
inline void reset() { _requiresReset = true; }
inline void markForReset() { _requiresReset = true; }
private:
uint16_t _dataLen = 0;
bool _requiresReset = false;

View File

@ -67,7 +67,12 @@
//do not call this method from system context (network callback)
void WS2812FX::finalizeInit(void)
{
RESET_RUNTIME;
//reset segment runtimes
for (uint8_t i = 0; i < MAX_NUM_SEGMENTS; i++) {
_segment_runtimes[i].markForReset();
_segment_runtimes[i].resetIfRequired();
}
_hasWhiteChannel = _isOffRefreshRequired = false;
//if busses failed to load, add default (fresh install, FS issue, ...)
@ -373,7 +378,7 @@ void WS2812FX::setMode(uint8_t segid, uint8_t m) {
if (_segments[segid].mode != m)
{
_segment_runtimes[segid].reset();
_segment_runtimes[segid].markForReset();
_segments[segid].mode = m;
}
}
@ -612,12 +617,12 @@ void WS2812FX::setSegment(uint8_t n, uint16_t i1, uint16_t i2, uint8_t grouping,
seg.spacing = spacing;
}
if (offset < UINT16_MAX) seg.offset = offset;
_segment_runtimes[n].reset();
_segment_runtimes[n].markForReset();
}
void WS2812FX::restartRuntime() {
for (uint8_t i = 0; i < MAX_NUM_SEGMENTS; i++) {
_segment_runtimes[i].reset();
_segment_runtimes[i].markForReset();
}
}
@ -648,9 +653,9 @@ void WS2812FX::resetSegments() {
_segments[i].cct = 127;
_segments[i].speed = DEFAULT_SPEED;
_segments[i].intensity = DEFAULT_INTENSITY;
_segment_runtimes[i].reset();
_segment_runtimes[i].markForReset();
}
_segment_runtimes[0].reset();
_segment_runtimes[0].markForReset();
}
void WS2812FX::makeAutoSegments() {