You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Colour pipeline can be freed while an encode or power estimate is using it; hold it by shared_ptr (compiled out on tiny-memory targets) #4440
A channel's colour pipeline can be freed while something is still using it.
fl::Channel owns its derived StreamingPipelineQ16 as a fl::unique_ptr (Channel::ColorPipelineStorage, src/fl/channels/channel.h). Everything that reads it takes a raw pointer:
user
where
how long it holds the pointer
the encode
Channel::showPixels hands mPipeline.get() to ReorderingPixelIteratorAny / ColorManagedPixelSource
CLEDController::colorPipeline() returns const StreamingPipelineQ16* to controller_unscaled_power_mW()
one full-strip pass
Channel::reconcileColorProfile() starts with mPipeline.reset(), and it runs whenever the channel is reconfigured:
applyConfig
setColorProfile / clearColorProfile via a new config
If that happens while an encode or an estimate is in flight (another task, a driver callback, or an async show), the reader is left holding a dangling pointer: a use-after-free. With a single owner there is no way for a reader to keep the pipeline alive.
Fix
Channel::ColorPipelineStorage becomes fl::shared_ptr<StreamingPipelineQ16>, built with fl::make_shared.
reconcileColorProfile() then only drops the channel's own reference.
A reader that took one keeps a valid pipeline until it finishes.
The existing test assertion sizeof(ColorPipelineStorage) <= 2 * sizeof(void*) still holds: a shared pointer is a pointer and a control-block pointer.
Every reader takes a reference for the duration of its use:
showPixels copies mPipeline into a local shared_ptr before setting flux and building the iterator, and keeps it until the encode returns.
The power estimate gets a shared_ptr from the controller accessor, not a raw pointer.
Small-memory devices pay nothing. All of this sits under FL_COLOR_PROFILE_RUNTIME, which is !FL_PLATFORM_HAS_TINY_MEMORY. On those targets (AVR and other tiny-memory parts) the following are all compiled out:
A test proves the lifetime: take a reader's reference, reconfigure or clear the channel, and the reader's pipeline is still valid and unchanged (checked under ASAN via bash test <name> --debug). The channel's own pipeline is gone or replaced.
uno Blink flash and RAM are byte-identical to master.
The ESP32-S3 bloat gate moves only by the documented amount.
bash test --cpp and bash lint pass.
Part of #4034 (colour pipeline program); touches P6 (#4040) and #4344.
Activity
fix(color): hold a channel's pipeline by shared_ptr; compile it all o…
chore(bloat): claim +116 B for shared pipeline ownership (#4440)
fix(color): never write the shared pipeline; gate the shared-only tests
feat(power): charge a managed channel's solved drives; hold the pipel…
chore(bloat): claim +2 B for the frame-local pipeline copy (#4440)
chore(bloat): claim +2 B for the frame-local pipeline copy (#4440) (#…