nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.22k stars 1.46k forks source link

Rasing an exception leaks memeory in `orc` #23714

Closed doongjohn closed 2 weeks ago

doongjohn commented 2 weeks ago

Description

Rasing an exception leaks memeory in orc

try:
  raise newException(Exception, "test")
except Exception as err:
  echo "exception: ", err.msg

Wrapping it in a proc does not help

proc a =
  try:
    raise newException(Exception, "test")
  except Exception as err:
    echo "exception: ", 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: 0b5a938f571133f6e876938387e37199d4c2ec16 active boot switches: -d:release

Current Output

nim c --mm:orc -d:useMalloc main.nim && valgrind --leak-check=full --show-leak-kinds=all ./main

==2344== Memcheck, a memory error detector
==2344== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==2344== Using Valgrind-3.23.0 and LibVEX; rerun with -h for copyright info
==2344== Command: ./main
==2344== 
exception: test
==2344== 
==2344== HEAP SUMMARY:
==2344==     in use at exit: 16,384 bytes in 1 blocks
==2344==   total heap usage: 4 allocs, 3 frees, 17,520 bytes allocated
==2344== 
==2344== 16,384 bytes in 1 blocks are still reachable in loss record 1 of 1
==2344==    at 0x4845794: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==2344==    by 0x4025C2: allocImpl__system_u1730 (in /home/..../src/main)
==2344==    by 0x4025E4: allocSharedImpl (in /home/..../src/main)
==2344==    by 0x40290E: init__system_u3292 (in /home/..../src/main)
==2344==    by 0x404959: registerCycle__system_u3415 (in /home/..../src/main)
==2344==    by 0x404B16: rememberCycle__system_u3455 (in /home/..../src/main)
==2344==    by 0x405F71: nimDecRefIsLastCyclicDyn (in /home/..../src/main)
==2344==    by 0x409091: eqdestroy___stdZtypedthreads_u202 (in /home/..../src/main)
==2344==    by 0x409ABD: NimMainModule (in /home/..../src/main)
==2344==    by 0x409903: NimMainInner (in /home/..../src/main)
==2344==    by 0x409914: NimMain (in /home/..../src/main)
==2344==    by 0x40994E: main (in /home/..../src/main)
==2344== 
==2344== LEAK SUMMARY:
==2344==    definitely lost: 0 bytes in 0 blocks
==2344==    indirectly lost: 0 bytes in 0 blocks
==2344==      possibly lost: 0 bytes in 0 blocks
==2344==    still reachable: 16,384 bytes in 1 blocks
==2344==         suppressed: 0 bytes in 0 blocks
==2344== 
==2344== For lists of detected and suppressed errors, rerun with: -s
==2344== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Expected Output

no leak

Possible Solution

No response

Additional Information

arc and refc does not leak.

Araq commented 2 weeks ago

That's not a leak, it is a single alloc that ORC needs for functioning.