Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

newruntime: undetected dangling ref #11350

Closed
Araq opened this issue May 29, 2019 · 0 comments

Comments

@Araq
Copy link
Member

commented May 29, 2019

In the following program the dangling pointer is not detected:

type
  Node = ref object
    data: int

proc main =
  var x = Node(data: 3) # inferred to be an ``owned ref``
  var dangling = unown x
  assert dangling.data == 3
  #dangling = nil
  # reassignment causes the memory of what ``x`` points to to be freed:
  x = Node(data: 4)
  # accessing 'dangling' here is invalid as it is nil.
  # at scope exit the memory of what ``x`` points to is freed
  if dangling != nil:
    echo dangling.data

main()

@Araq Araq added the New runtime label May 29, 2019

@Araq Araq closed this in 085a21e Jul 7, 2019

narimiran added a commit that referenced this issue Jul 8, 2019

fixes #11350
(cherry picked from commit 085a21e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.