Skip to content

Fix audio context and microphone listener cleanup leaks#325

Merged
zortos293 merged 1 commit intodevfrom
capy/fix-memory-leak-audio-mic-cleanup
Apr 16, 2026
Merged

Fix audio context and microphone listener cleanup leaks#325
zortos293 merged 1 commit intodevfrom
capy/fix-memory-leak-audio-mic-cleanup

Conversation

@zortos293
Copy link
Copy Markdown
Collaborator

@zortos293 zortos293 commented Apr 16, 2026

This PR fixes memory/resource leaks in the WebRTC audio and microphone management paths by ensuring explicit cleanup of native audio objects and stream listeners.

Main changes:

  • GfnWebRtcClient (opennow-stable/src/renderer/src/gfn/webrtcClient.ts):

    • Added audioSourceNode field to track the MediaStreamAudioSourceNode used for remote audio routing.
    • Introduced cleanupAudioRouting() helper to idempotently disconnect the source node, close the AudioContext, and reset the audio element state.
    • Modified cleanupPeerConnection() to call cleanupAudioRouting() instead of inline logic.
    • Updated audio track attachment to build the routing graph using local variables first; instance fields are only assigned after successful setup.
    • On setup failure or fallback, partially created objects are now cleaned up before startDirectAudioPlayback() is invoked.
  • MicrophoneManager (opennow-stable/src/renderer/src/gfn/microphoneManager.ts):

    • Replaced the anonymous inactive stream listener with a stable, stored handler (handleMicStreamInactive).
    • Added attachMicStream(), detachMicStreamListeners(), and clearMicStream() helpers to manage listener lifecycle.
    • Modified startCapture() to clear previous streams and attach listeners via attachMicStream().
    • Updated stop() to use clearMicStream() instead of inline cleanup.
    • Ensured the OverconstrainedError fallback path also attaches listeners correctly.

Open OPE-068 OPE-068

@zortos293 zortos293 added the capy Generated by capy.ai label Apr 16, 2026 — with Capy AI
@zortos293 zortos293 merged commit f55255e into dev Apr 16, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

capy Generated by capy.ai

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant