Skip to content

Reference Cycle cause memory leak in wasm, native backend #879

@illusory0x0

Description

@illusory0x0

Code

///|
struct Cycle {
  mut val : Cycle?
}

///|
test {
  let x = Cycle::{ val: None }
  x.val = Some(x)
  x |> ignore
}

Enable Address Sanitizer

{
  "link": {
    "native": {
      "cc-flags": "-fsanitize=address",
      "stub-cc-flags": "-fsanitize=address"
    }
  },
  "warn-list": "-A"
}

Error Message

Warning: package `username/hello/foo` has native cc, cc-flags, or cc-link-flags. `tcc run` will be disabled

=================================================================
==11253==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 16 byte(s) in 1 object(s) allocated from:
    #0 0x7d48670fd9c7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x5de2d2f78708 in moonbit_malloc_inlined /home/illu/dev.mbt/hello/target/native/debug/test/foo/foo.internal_test.c:49
    #2 0x5de2d2f7a016 in $username$hello$foo$__test_666f6f2e6d6274_0 /home/illu/dev.mbt/hello/target/native/debug/test/foo/foo.internal_test.c:2063
    #3 0x5de2d2f78874 in $username$hello$foo$__test_666f6f2e6d6274_0$dyncall /home/illu/dev.mbt/hello/target/native/debug/test/foo/foo.internal_test.c:1608
    #4 0x5de2d2f791ac in $username$hello$foo$moonbit_test_driver_internal_execute /home/illu/dev.mbt/hello/target/native/debug/test/foo/foo.internal_test.c:1838
    #5 0x5de2d2f8838c in main /home/illu/dev.mbt/hello/target/native/debug/test/foo/foo.internal_test.c:6391
    #6 0x7d4866c2a1c9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #7 0x7d4866c2a28a in __libc_start_main_impl ../csu/libc-start.c:360
    #8 0x5de2d2f78624 in _start (/home/illu/dev.mbt/hello/target/native/debug/test/foo/foo.internal_test.exe+0x3624) (BuildId: ef99bc438f88c4bd98b002a11f2a6c5f9cc683a2)

SUMMARY: AddressSanitizer: 16 byte(s) leaked in 1 allocation(s).
Failed to run the test: /home/illu/dev.mbt/hello/target/native/debug/test/foo/foo.internal_test.exe

Total tests: 1, passed: 0, failed: 1.

environment variables

export MOON_CC=gcc
# set MOON_CC to disable link libmoonbitrun.o 
# https://github.com/moonbitlang/moon/issues/755

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions