Skip to content

It's possible to leak a ref outside of a let block in tests #1260

Open
@TimDeve

Description

@TimDeve

Running this code gives an address-sanitizer warning in clang as we're letting a reference leak out of it's scope (the string the ref point to is deleted when the let scope is exited)

(Debug.sanitize-addresses)

(load "Test.carp")

(use Test)

(deftest test
  (assert-equal test
    "Wow"
    (let [s @"Wow"]
      &s)
    "Shouldn't compile"))

Doing the same outside a test does give the proper error

(defn main []
  (IO.println (let [s @"Wow"]
                &s)))
The reference '(let [s (String.copy "Wow")] (ref s))' (depending on the variable 's') isn't alive

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmemoryBorrow checker and lifetimes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions