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

[GC] Illegal storage access when collecting cycle #4851

Open
arnetheduck opened this issue Oct 3, 2016 · 3 comments
Open

[GC] Illegal storage access when collecting cycle #4851

arnetheduck opened this issue Oct 3, 2016 · 3 comments
Labels

Comments

@arnetheduck
Copy link
Contributor

The following causes a crash:

$ nim --version
Nim Compiler Version 0.15.0 (2016-10-03) [Linux: amd64]
Copyright (c) 2006-2016 by Andreas Rumpf

git hash: 6e1313515df4ee5808c77af5aeacfa77fce42474
$ nim c test ; ./test
Traceback (most recent call last)
test.nim(19)           test
system.nim(347)          prepareDealloc
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

$ nim c -d:useSysAssert test ; ./test
[SYSASSERT] CollectZCT: isAllocatedPtr

test.nim:

type
  PNode = ref TNode
  TNode = object
    le: PNode

proc finalizeNode(n: PNode) =
  var s = @[0]

proc returnTree() =
  var cycle: PNode
  new(cycle, finalizeNode)
  cycle.le = cycle

for i in 1..100:
  returnTree()

GC_fullCollect()
GC_fullCollect()
@yglukhov
Copy link
Member

yglukhov commented Oct 4, 2016

+1. Sometimes observed similar issue when used echo in a finalizer. Looks like anything that allocates inside finalizer may potentially crash the GC.

@genotrance
Copy link
Contributor

Still crashes with latest devel.

@ghost
Copy link

ghost commented Jun 23, 2020

Same behaviour on latest devel:

~/P/stuff ❯❯❯ nimq c seq.nim && ./seq
Traceback (most recent call last)
/home/dian/Projects/stuff/seq.nim(18) seq
/home/dian/Things/Nim/lib/system/gc_common.nim(417) prepareDealloc
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

~/P/stuff ❯❯❯ nimq c -d:useSysAssert seq.nim && ./seq
[SYSASSERT] CollectZCT: isAllocatedPtr

Although seems to work just fine with --gc:orc :)

~/P/stuff ❯❯❯ nimq c --gc:orc -d:useMalloc seq.nim
~/P/stuff ❯❯❯ valgrind --leak-check=full ./seq
==23485== Memcheck, a memory error detector
==23485== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==23485== Using Valgrind-3.16.0.GIT and LibVEX; rerun with -h for copyright info
==23485== Command: ./seq
==23485== 
==23485== 
==23485== HEAP SUMMARY:
==23485==     in use at exit: 0 bytes in 0 blocks
==23485==   total heap usage: 203 allocs, 203 frees, 1,689,952 bytes allocated
==23485== 
==23485== All heap blocks were freed -- no leaks are possible
==23485== 
==23485== For lists of detected and suppressed errors, rerun with: -s
==23485== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

arnetheduck added a commit to status-im/nim-secp256k1 that referenced this issue Dec 16, 2020
forgot about nim-lang/Nim#4851 when writing it

generally, will only be a problem if threads are created and destroyed
often
arnetheduck added a commit to status-im/nim-secp256k1 that referenced this issue Dec 16, 2020
forgot about nim-lang/Nim#4851 when writing it

generally, will only be a problem if threads are created and destroyed
often
arnetheduck added a commit to status-im/nim-nat-traversal that referenced this issue Dec 25, 2020
stefantalpalaru pushed a commit to status-im/nim-nat-traversal that referenced this issue Dec 25, 2020
@ringabout ringabout added the refc refc issues label Jan 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants