ORC leaking trivial object cycle
alaviss opened this issue · comments
In this simple graph of 3 objects linked into a ring, ORC did not collect this cycle.
Example
type
X = ref object
next: X
proc main() =
var x = X(next: X())
x.next.next = X(next: x)
x = nil # trying to rat out any scope bugs
echo "hi" # need a side-effect to prevent C from optimizing main away
main()
GC_fullCollect() # forcing orc hand
Actual Output
$ bin/nim r -d:release -d:useMalloc --passC:-fsanitize=address --passC:-fno-omit-frame-pointer --passC:-mno-omit-leaf-frame-pointer --debuginfo --linedir --passL:-fsanitize=address test.nim
hi
==82556==ERROR: LeakSanitizer: detected memory leaks
Indirect leak of 24 byte(s) in 1 object(s) allocated from:
#0 0x7f558d8d8cc7 in calloc (/lib64/libasan.so.8+0xd8cc7) (BuildId: 7fcb7759bc17ef47f9682414b6d99732d6a6ab0c)
#1 0x412684 in alloc0Impl__system_1722 /home/leorize/documents/sources/nimskull/lib/system/mm/malloc.nim:8
#2 0x412684 in alignedAlloc0__system_1892 /home/leorize/documents/sources/nimskull/lib/system/memalloc.nim:361
#3 0x412684 in nimNewObj /home/leorize/documents/sources/nimskull/lib/system/arc.nim:103
#4 0x413a7b in main__test_4 /home/leorize/documents/sources/nimskull/test.nim:6
#5 0x4146f6 in NimMainModule /home/leorize/documents/sources/nimskull/test.nim:10
#6 0x4146f6 in NimMain /home/leorize/documents/sources/nimskull/test.nim:1
#7 0x40136c in main /home/leorize/documents/sources/nimskull/test.nim:9
#8 0x7f558d646149 in __libc_start_call_main (/lib64/libc.so.6+0x28149) (BuildId: 788cdd41a15985bf8e0a48d213a46e07d58822df)
#9 0x7f558d64620a in __libc_start_main_impl (/lib64/libc.so.6+0x2820a) (BuildId: 788cdd41a15985bf8e0a48d213a46e07d58822df)
#10 0x4013e4 in _start (/home/leorize/.local/cache/nimskull/test_r/test_B09787AA776483F63DDBE28A81AC8FD72FB6A0A1+0x4013e4) (BuildId: 35e799e4318f1ed39dbe758e98cf68a3051ca74f)
Indirect leak of 24 byte(s) in 1 object(s) allocated from:
#0 0x7f558d8d8cc7 in calloc (/lib64/libasan.so.8+0xd8cc7) (BuildId: 7fcb7759bc17ef47f9682414b6d99732d6a6ab0c)
#1 0x412684 in alloc0Impl__system_1722 /home/leorize/documents/sources/nimskull/lib/system/mm/malloc.nim:8
#2 0x412684 in alignedAlloc0__system_1892 /home/leorize/documents/sources/nimskull/lib/system/memalloc.nim:361
#3 0x412684 in nimNewObj /home/leorize/documents/sources/nimskull/lib/system/arc.nim:103
#4 0x413aca in main__test_4 /home/leorize/documents/sources/nimskull/test.nim:7
#5 0x4146f6 in NimMainModule /home/leorize/documents/sources/nimskull/test.nim:10
#6 0x4146f6 in NimMain /home/leorize/documents/sources/nimskull/test.nim:1
#7 0x40136c in main /home/leorize/documents/sources/nimskull/test.nim:9
#8 0x7f558d646149 in __libc_start_call_main (/lib64/libc.so.6+0x28149) (BuildId: 788cdd41a15985bf8e0a48d213a46e07d58822df)
#9 0x7f558d64620a in __libc_start_main_impl (/lib64/libc.so.6+0x2820a) (BuildId: 788cdd41a15985bf8e0a48d213a46e07d58822df)
#10 0x4013e4 in _start (/home/leorize/.local/cache/nimskull/test_r/test_B09787AA776483F63DDBE28A81AC8FD72FB6A0A1+0x4013e4) (BuildId: 35e799e4318f1ed39dbe758e98cf68a3051ca74f)
Indirect leak of 24 byte(s) in 1 object(s) allocated from:
#0 0x7f558d8d8cc7 in calloc (/lib64/libasan.so.8+0xd8cc7) (BuildId: 7fcb7759bc17ef47f9682414b6d99732d6a6ab0c)
#1 0x412684 in alloc0Impl__system_1722 /home/leorize/documents/sources/nimskull/lib/system/mm/malloc.nim:8
#2 0x412684 in alignedAlloc0__system_1892 /home/leorize/documents/sources/nimskull/lib/system/memalloc.nim:361
#3 0x412684 in nimNewObj /home/leorize/documents/sources/nimskull/lib/system/arc.nim:103
#4 0x413a69 in main__test_4 /home/leorize/documents/sources/nimskull/test.nim:6
#5 0x4146f6 in NimMainModule /home/leorize/documents/sources/nimskull/test.nim:10
#6 0x4146f6 in NimMain /home/leorize/documents/sources/nimskull/test.nim:1
#7 0x40136c in main /home/leorize/documents/sources/nimskull/test.nim:9
#8 0x7f558d646149 in __libc_start_call_main (/lib64/libc.so.6+0x28149) (BuildId: 788cdd41a15985bf8e0a48d213a46e07d58822df)
#9 0x7f558d64620a in __libc_start_main_impl (/lib64/libc.so.6+0x2820a) (BuildId: 788cdd41a15985bf8e0a48d213a46e07d58822df)
#10 0x4013e4 in _start (/home/leorize/.local/cache/nimskull/test_r/test_B09787AA776483F63DDBE28A81AC8FD72FB6A0A1+0x4013e4) (BuildId: 35e799e4318f1ed39dbe758e98cf68a3051ca74f)
SUMMARY: AddressSanitizer: 72 byte(s) leaked in 3 allocation(s).
Additional Information
- I could not reproduce this with Nim, suggesting a nimskull bug
Information
$ bin/nim --version
Nimskull Compiler Version 0.1.0-dev.21153 [linux: amd64]
Source hash: 2841c11f922821e645ef0d6822b671a8fb679127
Source date: 2024-01-17
active boot switches: -d:release