Callback state must outlive the object that releases the borrowed buffer
Symptom#
ASan reports stack-use-after-scope when a borrowed-buffer release callback writes to a local counter during object destruction.
Cause#
The counter is declared after the object that owns the borrowed column. Local objects are destroyed in reverse declaration order. The counter's lifetime ends before the owner calls the release callback.
Fix#
Declare the release counter before the objects that hold the borrowed buffer. The counter then outlives their destruction.
Evidence#
Inbox note 0164c558e8, dated 2026-10-02, records this trap in dftracer-utils borrowed string-view tests. A release-counter int declared after a DataFrame died first, so its callback wrote to a dead stack slot. The note gives the fix: declare counters before frames. This distillation did not rerun the test.
Also found by searching
- ASan stack-use-after-scope
- release callback writes to a dead stack counter when a borrowed frame is destroyed
- how do I keep a release callback counter alive until its owner is destroyed
- destruction order makes a borrowed buffer test access an expired local variable