Skip to content

Fix various memory correctness issues - #456

Merged
stintel merged 4 commits into
mainfrom
fix/memory_issues
Jul 21, 2026
Merged

stintel merged 4 commits into
mainfrom
fix/memory_issues

Conversation

@stintel

@stintel stintel commented Jul 20, 2026 •

Copy link
Copy Markdown
Collaborator

These issues were uncovered during an LLM-assisted code audit. See individual commit messages for details.

Torture test results: 1000/1000.

stintel added 4 commits July 20, 2026 09:17
Read one byte less than the buffer size to guarantee space for
the null terminator. If esp_http_client_read returns exactly
2048 bytes, buf[read_len] = 0 writes one byte past the allocation.

Reported-by: Claude Opus 4.6 <noreply@anthropic.com>
Fixes: e102adf ("test2: feed audio to HTTP API")
The WebSocket event callback runs in the WebSocket client task rather
than an interrupt context. It performs substantial JSON, UI, and
storage processing and has no demonstrated requirement to reside in
IRAM.

Allow the callback to use normal application code placement and avoid
unnecessarily consuming internal instruction memory.

This reverts commit 7e0ba91.

Reported-by: Claude Opus 4.6 <noreply@anthropic.com>
audio_element_set_event_callback() expects an audio_element_handle_t,
but the playback callback was passed the esp_audio_handle_t. Treating
the ESP Audio controller as an audio element corrupted unrelated
controller memory, including its volume configuration.

Passing the playback HTTP element instead would avoid that corruption,
but would not make the callback usable. ESP Audio owns the element,
temporarily replaces its single event callback while probing the codec,
and then clears it. Callback delivery would also bypass the listener
ESP Audio uses to manage pipeline events.

The playback callback therefore cannot provide the intended error
handling. Remove its registration and leave the independent callback on
the standalone STT HTTP element unchanged.

Reported-by: GPT-5.6-sol
Fixes: 86353e1 ("audio: add callback for HTTP stream audio element")
The IP event handler remains registered after the initial connection
and uses hdl_evg for every GOT_IP event. Deleting the event group after
the first connection leaves the handler with a stale handle on later
reconnections.

Keep the event group alive for the lifetime of the registered handler.

Reported-by: GPT-5.6-sol
Fixes: eb812b4 ("network: nuke periph_wifi")
@stintel
stintel force-pushed the fix/memory_issues branch from d33c17a to 1981376 Compare July 20, 2026 08:10
@stintel
stintel merged commit 6a07344 into main Jul 21, 2026
9 checks passed
@stintel
stintel deleted the fix/memory_issues branch July 21, 2026 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant