Skip to content

Taking ownership of value captured by a lambda env is unsafe  #1040

Open
@TimDeve

Description

@TimDeve

The following example will result in a double free:

(defn main []
  (let [s @"String"
        f (fn [] s)]
    (ignore (f))))

The reason is that returning the value s means the consumer of the lambda will take ownership of it, so when it is done with the value it will call delete on it, but the value is still captured in the env of the lambda so when the env gets deleted it tries to free something already free-ed.

For the same reason calling a function that take ownership in the lambda will result in the same problem:

(defn main []
  (let [s @"String"
        f (fn [] (ignore s))]
    (f)))

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions