Skip to content

Smart pointers and memory management cleanup#10400

Merged
thebentern merged 8 commits intomasterfrom
ptr
May 6, 2026
Merged

Smart pointers and memory management cleanup#10400
thebentern merged 8 commits intomasterfrom
ptr

Conversation

@thebentern
Copy link
Copy Markdown
Contributor

No description provided.

@thebentern thebentern requested review from Copilot and jp-bennett May 6, 2026 12:21
@thebentern thebentern added the cleanup Code cleanup or refactor label May 6, 2026
@github-actions github-actions Bot added the needs-review Needs human review label May 6, 2026
@github-actions github-actions Bot added the enhancement New feature or request label May 6, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_ptr for safer ownership and automatic cleanup (PacketHistory, RotaryEncoderImpl, Portduino CH341 probe, Syslog formatting buffer).
  • Introduce a free()-based deleter for StoreForward’s ps_calloc/calloc-allocated packet history buffer.
  • Add a concurrency::Lock destructor 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().

Comment thread src/DebugConfiguration.cpp Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Comment thread src/mesh/PacketHistory.h
@thebentern thebentern merged commit 220bb4d into master May 6, 2026
80 checks passed
@thebentern thebentern deleted the ptr branch May 6, 2026 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup Code cleanup or refactor enhancement New feature or request needs-review Needs human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants