Smart pointers and memory management cleanup#10400
Merged
thebentern merged 8 commits intomasterfrom May 6, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors several Portduino/platform and module components to use RAII/smart pointers instead of manual new/delete, and adds proper cleanup for the FreeRTOS concurrency::Lock semaphore handle.
Changes:
- Replace raw heap allocations with
std::unique_ptrfor safer ownership and automatic cleanup (PacketHistory, RotaryEncoderImpl, Portduino CH341 probe, Syslog formatting buffer). - Introduce a
free()-based deleter for StoreForward’sps_calloc/calloc-allocated packet history buffer. - Add a
concurrency::Lockdestructor to delete the underlying FreeRTOS semaphore.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/platform/portduino/PortduinoGlue.cpp | Use std::unique_ptr for CH341 probing to avoid manual delete paths. |
| src/modules/StoreForwardModule.h | Store packet history as unique_ptr with a free() deleter (matches calloc/ps_calloc). |
| src/modules/StoreForwardModule.cpp | Allocate packet history via reset() into the RAII-managed pointer. |
| src/mesh/PacketHistory.h | Replace raw PacketRecord* with std::unique_ptr<PacketRecord[]> and remove manual destructor. |
| src/mesh/PacketHistory.cpp | Update allocations/iteration to use unique_ptr::get() and rely on implicit cleanup. |
| src/input/RotaryEncoderImpl.h | Convert RotaryEncoder* to std::unique_ptr<RotaryEncoder>. |
| src/input/RotaryEncoderImpl.cpp | Remove manual delete logic; use unique_ptr::reset() for allocation. |
| src/DebugConfiguration.cpp | Use std::unique_ptr<char[]> for syslog formatting buffer (but see PR comment). |
| src/concurrency/Lock.h | Add destructor declaration. |
| src/concurrency/Lock.cpp | Implement FreeRTOS semaphore deletion in Lock::~Lock(). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.