feat: add alloc-tracking#266
Open
Ben Chatelain (phatblat) wants to merge 2 commits into
Open
Conversation
58ce4a9 to
32fc2be
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves SDKS-1896
Extracted from getditto/ditto#18937
Summary
Adds an opt-in
alloc-trackingCargo feature that records allocation, deallocation, and Arc clone/drop events with backtraces to help diagnose use-after-free, double-free, and Arc refcount bugs in FFI code.Changes
alloc-trackingfeature (off by default) gated on a new optionalbacktracedependencysrc/alloc_tracking.rsmodule exposingAllocationTrackerwith:track_alloc/track_freeforBox/Vec/slice/char_pallocations (double-free and unknown-pointer-free panics)track_arc_new/track_arc_clone/track_arc_dropforArcrefcount eventsALLOC_TRACKERbehind aLazyLock<Mutex<…>>ThinArc(src/arc.rs)ThinBox(src/boxed.rs)char_p::Box/CStringconversions (src/char_p.rs)slice_boxed(src/slice.rs), skipping zero-length and ZST allocationsVecFFI wrapper (src/vec.rs)Arc/Boxwrappers (src/closure/arc.rs,src/closure/boxed.rs)serial_testdev-dependency (tracker state is global, so tests must not run in parallel)Notes
All instrumentation is behind
#[cfg(feature = "alloc-tracking")]and has zero runtime cost when the feature is disabled.cargo check --all-featuresdoes not work on this branch or onmaster— it activates thenightlyfeature (which requires a nightly toolchain) and hits a pre-existing serdevisit_byte_bufmismatch insrc/bytes.rs. Use the targeted commands below instead.Test plan
cargo check --features alloc-trackingcargo test --features alloc-trackingcargo check(default features, verify no regression from feature-gating)