Skip to content

Fix undefined behavior and memory leak in AfskModulator - #809

Open
MarkRose wants to merge 1 commit into
sm0svx:masterfrom
MarkRose:fix-afskmodulator-empty-deque
Open

Fix undefined behavior and memory leak in AfskModulator#809
MarkRose wants to merge 1 commit into
sm0svx:masterfrom
MarkRose:fix-afskmodulator-empty-deque

Conversation

@MarkRose

Copy link
Copy Markdown
Contributor
  • Fix undefined-behavior read of back() on an empty deque during
    end-of-frame fade-out. When the last symbol is popped from bitbuf
    in writeToSink(), the deque becomes empty; the fade-out code then
    refilled it with bitbuf.push_back(bitbuf.back()), reading from an
    empty container on the first iteration. This fired at the end of
    every AFSK burst. Capture the last transmitted bit before popping
    it and use that saved value to refill the deque instead.

  • Free the sin_lookup and exp_lookup heap-allocated lookup tables in
    ~AfskModulator(); they were allocated with new[] in the constructor
    but never released, leaking on every destruction of the modulator.

Co-Authored-By: Claude Opus 4.8 [email protected]

- Fix undefined-behavior read of back() on an empty deque during
  end-of-frame fade-out. When the last symbol is popped from bitbuf
  in writeToSink(), the deque becomes empty; the fade-out code then
  refilled it with bitbuf.push_back(bitbuf.back()), reading from an
  empty container on the first iteration. This fired at the end of
  every AFSK burst. Capture the last transmitted bit before popping
  it and use that saved value to refill the deque instead.

- Free the sin_lookup and exp_lookup heap-allocated lookup tables in
  ~AfskModulator(); they were allocated with new[] in the constructor
  but never released, leaking on every destruction of the modulator.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@MarkRose MarkRose closed this Jul 12, 2026
@MarkRose MarkRose reopened this Jul 12, 2026
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