Skip to content

pcre2-test heap-8 red on linux-x86_64: find_limits frees the match data's heap frames, which C pcre2 keeps #2365

Closed

Description

@ehartford

What fails

pcre2-test is red on linux-x86_64 (eric-5090, Ubuntu, glibc 2.43) at main
c97a008, built from the pinned seed nightly-20261011-local-2-e4861e1d6997.
It is also red at PR #2361's head, so the failure predates that PR. Only one
test in the suite differs, heap-8:

--- testdata/testoutputheap-8
+++ testoutput8/testoutputheap-8
@@ -32,7 +32,7 @@
  0: abcd
  1: cd
     abcd\=memory,ovector=0
-free    40960
+free unremembered block
 free unremembered block

Direct repro: out/pcre2_build/bin/pcre2test -q testinputheap out.txt, run in
out/pcre2_reference/pcre2-10.47/testdata.

What gdb shows (watchpoint on malloclistptr; breakpoints on my_malloc and my_free)

  1. The block is recorded. Pattern 2's \=memory match grows the heap
    frames: my_malloc(40960) from match_ (pcre2_match.w:4646) returns
    0x7ffff7f1e010. pcre2test records it (malloclistptr 1 -> 2). The old
    20480 block is freed and removed (2 -> 1).
  2. It is freed while tracking is off. Pattern 2's \=find_limits, with
    show_memory off, then runs the match repeatedly. During those retries,
    my_free(0x7ffff7f1e010) frees that recorded 40960 block. The list isn't
    updated, because tracking is off, so its entry goes stale.
  3. The later free misses. Pattern 3's \=memory,ovector=0 frees the
    match data's current heap frames, which are no longer the recorded block:
    free unremembered block.

The expected output says that C pcre2 still holds the 40960 block at pattern 3,
so its find-limits retries do not free the match data's heap frames.
heapframes handling in the migrated pcre2_match (around
pcre2_match.w:893 and 1913 and match_ near 4646/4662) diverges from
the C: either the retries use the match data's vector where C would not, or the
vector is reallocated where C keeps it.

Next step

Build the reference pcre2test from out/pcre2_reference/pcre2-10.47 with the
host C compiler, run the same gdb script against it, and compare the first
my_malloc/my_free that differs. That points to the C statement the
migration changed. Per D112 the corpus moves only by re-promotion, so the fix
belongs in the migrator.

Why the Mac battery may be green

Unknown. The diff depends on allocation order and sizes. Check whether
pcre2-test passes on darwin-aarch64 at c97a008.

Activity

  1. added a commit that references this issue on Oct 12, 2026
  2. ehartford commented on Oct 12, 2026

    @ehartford
    ContributorAuthor

    Root cause: this isn't a pcre2 or migrator bug. check_match_limit (pcre2test_inc.h:3070) frees the cached heap frames on each find_limits retry while show_memory is off, so pcre2test's malloc list keeps a stale entry. Whether a later free prints its size depends only on malloc returning the same address.

    Evidence on eric-5090:

    • The C pcre2test built by gcc fails upstream's own testoutputheap-8 at pattern 2.
    • Under gdb, the C pcre2test and the migrated one make the same 146 my_malloc/my_free calls, with the same sizes, in the same order.
    • Our normalizer had rewritten the expected output to the Mac's address reuse.

    Fixed in #2361 (cb9205a): the heap test now compares every free as free. Allocation sizes, frame sizes, heapframes sizes and the order and count of frees still compare. pcre2-test is green on eric-5090. Follow-up audit: #2373.

  3. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): does not reproduce; #2361 (cb9205a) fixed the comparison as the comment above explains. Today the With-built and C-built pcre2test give identical heap output on Linux x86_64:

    # eric-5090, tree c88f3eeff
    $ out/wo-drift/pcre2/pcre2test -q -8 testdata/testinputheap with.txt
    $ out/pcre2_build/bin/pcre2test   -q -8 testdata/testinputheap c.txt
    $ diff c.txt with.txt
    (no output; rc 0)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions