Skip to content

Fix native VehicleDecoder leak in DashKitDataSource - #249

Merged
wpmed92 merged 1 commit into
softwiredtech:mainfrom
ehoeve786:fix/dashkit-decoder-leak
Oct 7, 2026
Merged

wpmed92 merged 1 commit into
softwiredtech:mainfrom
ehoeve786:fix/dashkit-decoder-leak

Conversation

@ehoeve786

Copy link
Copy Markdown
Collaborator

Problem

DashKitDataSource creates a native VehicleDecoder (via CanFrameDecoder) per connection but never frees it — CanFrameDecoder.destroy() has no callers. Every DashKit connect/reconnect from ConnectionViewModel (manual connect, foreground restore after a dead link) leaks a full decoder with its parsed DBC tables. CommaDataSource already frees its decoder in disconnect(); the DashKit path was missing it.

Fix

  • DashKitDataSource.disconnect() calls decoder.destroy() after removing the GATT listener.
  • CanFrameDecoder.destroy() zeroes the handle; decodeFrame() returns null once destroyed and the caller drops the packet. Both are @Synchronized, so a notification already in flight on the binder thread during teardown can't decode with a freed pointer.

BLE-level auto-reconnects (e.g. DashKit reboot) are unaffected — the data source and decoder persist across those as before.

Testing

Samsung Galaxy S23 Ultra, Android 16. dumpsys meminfo taken ~1 min apart across repeated DashKit connect/disconnect cycles:

  • Stock v0.9.2: native heap 17.0 → 78.6 MB (+61.6 MB, ≈8–9 leaked decoders)
  • v0.9.1 + this fix: native heap 21.0 → 22.3 MB (+1.2 MB, flat)

Host build of VehicleDecoder with config_dashkit.json: one decoder ≈ 7.2 MB native; 10 cycles leak 71.6 MB without destroy(), 0.05 MB with it.

🤖 Generated with Claude Code

meminfo-fixed-v0.9.1-after.txt
meminfo-fixed-v0.9.1-before.txt
meminfo-stock-v0.9.2-after.txt
meminfo-stock-v0.9.2-before.txt

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017nzxRV1bnDuyu5Ma2AgR7q
@wpmed92
wpmed92 merged commit d0198ce into softwiredtech:main Oct 7, 2026
2 checks passed
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.

2 participants