SIGN IN SIGN UP
square / leakcanary UNCLAIMED

A memory leak detection library for Android.

0 0 74 Kotlin

HprofPrimitiveArrayStripper: fix bugs, add StreamingSinkProvider

Fix two correctness bugs:

- INSTANCE_DUMP: stackTraceSerialNumber is always u4 (4 bytes), not
  identifier-sized. This was silently corrupting output for heap dumps
  with 8-byte identifiers.
- PRIMITIVE_ARRAY_DUMP: CopyingSource.transferUnsignedByte() already
  copies the type byte to the sink — the extra sink.writeByte(type) call
  was writing it twice, corrupting all primitive array records.

Fix a third bug in CopyingSource.transferUtf8: it decoded bytes as
UTF-8 into a Java String then re-encoded, which produces different byte
counts for Modified UTF-8 sequences (used by HotSpot HPROF). The fix
reads the raw bytes and copies them unchanged, only decoding to String
for the return value.

Other changes:
- Add StreamingSinkProvider (mirrors StreamingSourceProvider) so the
  sink lifecycle is managed inside the function via .use {}
- Replace BufferedSink parameter with StreamingSinkProvider in the
  streaming overload
- Refactor parsing into a private stripPrimitiveArrays(CopyingSource)
  method
- Add CopyingSource.indexOf delegate
- Also updates all primitive wrapper instance values to 0 (in addition
  to primitive arrays), as an additional PII safety measure
- Add deleteInputHprofFile parameter to delete the input file eagerly
  after the source is opened, using the Unix trick
- Clean up test: replace raw-byte helpers with HprofWriter-based
  fixture, add JVM heap dump tests for string replacement and wrapper
  value zeroing

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
P
Pierre-Yves Ricau committed
a6b2310ce808495afdd44d0c83ec134bce6e0429
Parent: c2ddc5a