Skip to content

debug allocator: record the first free's return address so DOUBLE FREE names both sites without lldb #1014

Closed

Description

@ehartford

debug-alloc: DOUBLE FREE addr=… size=32 first_drop=drop#struct __drop_struct_16 second_drop=<untagged> names the first free's drop-origin tag but not its call site. Resolving the site today means lldb with a conditional breakpoint on rt_free (times out on real programs: every alloc/free with a backtrace) or a breakpoint on dbg_report_double_free (gives only the SECOND site).

Proposed: in debug-alloc mode, store the return address (and one or two frames up, via the frame pointer) at each free in the ledger entry, and print both sites symbolized (or as addresses for atos) in the DOUBLE FREE / invalid-free report. Same for the allocation site of a leaked block. This turns the most common lldb session for drop bugs into zero lldb sessions.

See docs/deep-debugging-tools.md review (2026-09-03); the 2026-09-03 spec_ss06 hunt is the motivating case.

Activity

  1. ehartford commented on Sep 4, 2026

    @ehartford
    ContributorAuthor

    Narrowing after reading rt/rt_core.w: the allocator already has the per-address trap — WITH_DEBUG_ALLOC_TRAP_FREE=<decimal payload addr> prints every rt alloc and free of that address with its drop origin (works without WITH_DEBUG_ALLOC, so the heap layout is unchanged), and WITH_DEBUG_ALLOC_TRAP_FREE_HIT=<n> panics on the n-th free so a debugger stops on that chain (#747 instrument, rt_core.w ~line 758). Neither docs/deep-debugging-tools.md nor CLAUDE.md mentioned it, which is being fixed in the docs commit that retires the per-allocation lldb script. What remains of this issue: record the first free's return address in the ledger entry by default so the DOUBLE FREE / invalid-free report names both sites in the first run, without a second run under the trap env.

  2. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): reproduced: still missing. dbg_report_double_free (rt/rt_core.w:1548) prints the first and second drop-origin tags and no call site for either free. The address trap (WITH_DEBUG_ALLOC_TRAP_FREE, under lldb) remains the only way to get the first site.

    post-release: a debugging-tool improvement with a working route today.

  3. added this to the post-v0.16.0 milestone on Oct 28, 2026
  4. added a commit that references this issue on Nov 11, 2026
  5. ehartford commented on Nov 11, 2026

    @ehartford
    ContributorAuthor

    Fixed in #3257 for Darwin. The ledger entry keeps the allocation's calling chain (6 frames) and the first free's (8). A DOUBLE FREE prints 'first free' and 'second free' chains; the first 16 LEAK lines print 'allocated at'. Nothing is captured off the thread's own stack (a fiber or generator stack has no caller to unwind to; the first version crashed there, exit 139, found by the battery). Linux, Windows and wasm have no in-process unwinder in the runtime yet and print the tags as before. Cost: 2,000,000 alloc/free pairs under WITH_DEBUG_ALLOC, 0.09 s to 0.19 s. Tests: da_1014_double_free_names_first_site, da_1014_leak_names_alloc_site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions