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

Global objects are not freed with noMain #18262

Closed
planetis-m opened this issue Jun 14, 2021 · 0 comments · Fixed by #23357
Closed

Global objects are not freed with noMain #18262

planetis-m opened this issue Jun 14, 2021 · 0 comments · Fixed by #23357
Assignees

Comments

@planetis-m
Copy link
Contributor

Similar issue to #18215 but in regards to global objects

Example

type
  Foo = ref object
    data: string

var
  f = Foo(data: newStringOfCap(1000))
#include "fib.h"
#include <stdio.h>

int main(void)
{
  NimMain();
  return 0;
}

Compile with:

nim c --cc:clang --noMain --noLinking --header:fib.h -d:danger --gc:arc -d:usemalloc --panics:on -d:nosignalhandler fib.nim
clang -o m -I$HOME/.cache/nim/fib_r -Ipath/to/Nim/lib $HOME/.cache/nim/fib_r/*.c -fsanitize=leak maths.c

Btw I can't make leak sanitizer to detect this (even with -d:useMalloc), but it seems pretty obvious that global resources acquired in NimMain are never freed.

Possible Solution

Should there be a NimExit proc to be called manually at the end that handles destructions, unhandled exceptions... ?

$ nim -v
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2021-06-14
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: 2d34b1f5bc45a180d1b53d6c24857133859a4f46
active boot switches: -d:release --gc:markAndSweep
@ringabout ringabout self-assigned this Feb 27, 2024
ringabout added a commit that referenced this issue Feb 27, 2024
Araq pushed a commit that referenced this issue Mar 4, 2024
…atic/dynlib libraries (#23357)

fixes #20945
fixes #18262

todo
- [ ] perhaps export with lib prefix when the option is enabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants