Xo is experimental. The source is now public on GitHub, or try Xo in your browser.
Menu · XO0915

Docs

XO0915: a raw address used after its value was released

warning · reported by the vet --cost

Reported by xo vet --cost on std’s own code (the raw functions are std internals). A value is released right after its last named use, even inside the arguments of the call that takes its address, so f(raw.data(s), s.len()) releases s before f runs and f reads freed memory. The read is right while nothing reuses the block, so outputs rarely show it; a –race build on Linux reports a heap-use-after-free (gotchas/raw-address-outlives-bytes.md; the 2026-11-02 race stress found four in std). Keep the value alive past the last access.

Example

fn put_len(d: Int, n: Int) {
  let s = "${n}"
  copy(d, raw.data(s), s.len())
}

Fix

fn put_len(d: Int, n: Int) {
  let s = "${n}"
  copy(d, raw.data(s), s.len())
  raw.alive_str(s)
}

Run xo explain XO0915 for this text in a terminal, or see section 10.6 of the specification.