Skip to content

fixes #25992; fix GC tracing of stale bytes in case objects during reset - #26003

Open
ringabout wants to merge 1 commit into
develfrom
pr_case_reset_refc
Open

fixes #25992; fix GC tracing of stale bytes in case objects during reset#26003
ringabout wants to merge 1 commit into
develfrom
pr_case_reset_refc

Conversation

@ringabout

Copy link
Copy Markdown
Member

fixes #25992

type
  Foo = object
    case kind: bool
    of true:
      a: ref Bar   # 8 bytes (pointer)
    of false:
      b: int       # 4 bytes

specializeResetT for b emits accessor.b = 0 — writes 4 bytes
But the union is 8 bytes wide (sized by the largest branch)
The remaining 4 bytes where a used to live are untouched
Those stale bytes could contain a heap pointer the GC traces → crash

Add nimZeroMem after specializeResetN for case objects to clear the
entire union including unused branch bytes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refc SIGSEGV on var r = V(g: true, v: A()); discard move r; GC_fullCollect() on case object

1 participant