Skip to content

[Fix] Issue-567: Out of Memory crashes in Sub-Ghz#569

Open
Lechnio wants to merge 1 commit into
Next-Flip:devfrom
Lechnio:Lechnio/fix/issue-567
Open

[Fix] Issue-567: Out of Memory crashes in Sub-Ghz#569
Lechnio wants to merge 1 commit into
Next-Flip:devfrom
Lechnio:Lechnio/fix/issue-567

Conversation

@Lechnio

@Lechnio Lechnio commented Jul 12, 2026

Copy link
Copy Markdown

What's new

  • [Describe changes here]

Fixed for issue 567

For the reviewer

  • I've uploaded the firmware with this patch to a device and verified its functionality
  • I've confirmed the bug to be fixed / feature to be stable

@Lechnio
Lechnio force-pushed the Lechnio/fix/issue-567 branch from d60a7dd to 351c63f Compare July 13, 2026 10:19
lewisQ17 added a commit to lewisQ17/Momentum-Firmware that referenced this pull request Jul 19, 2026
…ore RAM")

Addresses the SubGHz Out-Of-Memory crashes (Next-Flip#567/Next-Flip#555). Adopts the safe parts
of the community PR Next-Flip#569, deliberately EXCLUDING the RX worker stream halving
(16->8 KB in subghz_worker.c), which trades RX capture headroom for RAM and
needs on-hardware validation on dense signals.

* keeloq encoder (lib/subghz/protocols/keeloq.c): allocate the upload buffer
  lazily and size it to the frame's actual worst case in get_upload(), instead
  of a fixed 1100 entries (~4.4 KB) held for the encoder's whole life. Frees
  ~4.4 KB of resident heap and closes a latent overflow for >64-bit variants
  (furi_check(upindex <= need) bounds it).

* Pre-flight heap gating: Flipper's malloc traps on OOM, so a TX/decode started
  with insufficient (or too fragmented) heap crashes. subghz_txrx_tx_start,
  raw.c encoder_worker_init and the decode-RAW scene now check
  memmgr_get_free_heap()/max_free_block() first and fail gracefully — a
  "Not enough memory" dialog (subghz_i.c) instead of a crash.

* file-encoder worker: reserve the RAW_Data line buffer up front so
  stream_read_line never reallocs (realloc traps on OOM) mid-transmit, and
  size the playback stream buffer accordingly.

* decode-RAW scene: free the worker as soon as playback finishes (was held
  until exit), on top of the earlier double-free/NULL-guard fixes.

* history: raise the free-heap reserve 4->8 KB so a burst of receptions leaves
  room for a later TX allocation.

* transmitter restore path uses the low-level subghz_txrx_tx_start so the
  silent rolling-counter restore never pops the memory dialog.

Verified: clean fbt build. RX worker buffer left at 16 KB (unchanged).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JA9f5sJuwNgBwBNqHWsx2h
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