Ray's Knowledge Base
Unlock

Keep winlist backing storage alive until frame_op copies it

PitfallVerified 30 Sep 2026Holds project: dftracer-utils
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

A session-stage implementation builds successfully but passes a dangling data pointer through OpArgs.

Cause#

winlist was given a temporary vector. OpArgs retained its data pointer after the temporary died, before frame_op copied it.

Fix#

Use a local vector whose lifetime includes the frame_op call rather than a temporary passed to winlist.

Evidence#

Transcript b1cb9c733a explicitly identifies the pointer lifetime and replaces the temporary with a local vector. It later reports the session tests passed. This was found by reading the code; the extract does not show a runtime crash.

Also found by searching

  • OpArgs holds dangling data pointer from winlist given a temporary std::vector before frame_op
  • session stage builds fine but passes freed memory into the frame operator arguments
  • how do I keep the vector passed to winlist alive long enough for frame_op to copy it
  • temporary vector lifetime ends before op call, pointer stored in args struct, use named local
  • OpArgs holds a dangling data pointer after winlist given temporary vector, frame_op copies later
  • session stage compiles but pointer into freed vector passed to frame_op
  • how do I keep vector storage alive until frame_op copies the window list
  • c++ temporary vector passed to winlist, data() pointer stored in OpArgs outlives it