Open
Description
Description
Seq IndexDefect leaks memeory in arc
and orc
.
try:
var a = @[0]
a[1] = 0 # <-- IndexDefect this leaks
# raise newException(IndexDefect, "") # <-- this does not leak
# echo 10 div 0 # <-- this does not leak
# assert(false) # <-- this does not leak
except Defect as err:
echo "defect: ", err.msg
Wrapping it in a proc does not help
proc a =
try:
var a = @[0]
a[1] = 0
except Defect as err:
echo "defect: ", err.msg
a()
Nim Version
Nim Compiler Version 2.1.1 [Linux: amd64]
Compiled at 2024-06-12
Copyright (c) 2006-2024 by Andreas Rumpf
git hash: 0b5a938
active boot switches: -d:release
Current Output
nim c --mm:arc -d:useMalloc main.nim && valgrind --leak-check=full --show-leak-kinds=all ./main
==5609== Memcheck, a memory error detector
==5609== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==5609== Using Valgrind-3.23.0 and LibVEX; rerun with -h for copyright info
==5609== Command: ./main
==5609==
defect: index 1 not in 0 .. 0
==5609==
==5609== HEAP SUMMARY:
==5609== in use at exit: 16 bytes in 1 blocks
==5609== total heap usage: 7 allocs, 6 frees, 1,218 bytes allocated
==5609==
==5609== 16 bytes in 1 blocks are still reachable in loss record 1 of 1
==5609== at 0x484CA2F: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==5609== by 0x405C88: alloc0Impl__system_u1732 (in /home/..../src/main)
==5609== by 0x405CAA: allocShared0Impl__system_u1745 (in /home/..../src/main)
==5609== by 0x405CDF: alignedAlloc0__system_u1910 (in /home/..../src/main)
==5609== by 0x406686: newSeqPayload (in /home/..../src/main)
==5609== by 0x407211: NimMainModule (in /home/..../src/main)
==5609== by 0x407153: NimMainInner (in /home/..../src/main)
==5609== by 0x407164: NimMain (in /home/..../src/main)
==5609== by 0x40719E: main (in /home/..../src/main)
==5609==
==5609== LEAK SUMMARY:
==5609== definitely lost: 0 bytes in 0 blocks
==5609== indirectly lost: 0 bytes in 0 blocks
==5609== possibly lost: 0 bytes in 0 blocks
==5609== still reachable: 16 bytes in 1 blocks
==5609== suppressed: 0 bytes in 0 blocks
==5609==
==5609== For lists of detected and suppressed errors, rerun with: -s
==5609== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Expected Output
no leak
Possible Solution
No response
Additional Information
refc
does not leak.