softdevteam / yksom

Other
8 stars 6 forks source link

Memory leaks from RawVec? #193

Open ltratt opened 4 years ago

ltratt commented 4 years ago

We appear to have a minor memory leak in RawVec. If I run the (non-lang test) (tiny) test suite I get 9 warnings all of which look pretty much as below:

$ RUSTFLAGS=-Zsanitizer=address RUSTDOCFLAGS=-Zsanitizer=address cargo test --target x86_64-unknown-linux-gnu
...
Direct leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x561721956fdd in __interceptor_malloc /rustc/llvm/src/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:145:3
    #1 0x561721af1ede in alloc::alloc::alloc::hd188e3087967b4ce /home/ltratt/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/alloc.rs:75:14
    #2 0x561721af2241 in alloc::alloc::Global::alloc_impl::hc131b3611c7bd126 /home/ltratt/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/alloc.rs:154:73
    #3 0x561721af4e14 in _$LT$alloc..alloc..Global$u20$as$u20$core..alloc..AllocRef$GT$::alloc::hf0a40d552cfe068b /home/ltratt/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/alloc.rs:213:9
    #4 0x561721b4adfa in alloc::raw_vec::RawVec$LT$T$C$A$GT$::allocate_in::hff8ed03c420be35c /home/ltratt/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/raw_vec.rs:188:45
    #5 0x561721b4da0c in alloc::raw_vec::RawVec$LT$T$C$A$GT$::with_capacity_in::h7872b7cf7c975271 /home/ltratt/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/raw_vec.rs:163:9
    #6 0x561721af4104 in alloc::slice::_$LT$impl$u20$$u5b$T$u5d$$GT$::to_vec::h909759196844c9b7 /home/ltratt/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/slice.rs:395:9
    #7 0x561721b30f8b in _$LT$alloc..vec..Vec$LT$T$GT$$u20$as$u20$core..clone..Clone$GT$::clone::hab3cfc44ed179b14 /home/ltratt/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/vec.rs:1904:9
    #8 0x5617219d25b3 in _$LT$num_bigint..bigint..BigInt$u20$as$u20$core..clone..Clone$GT$::clone::h0a290b237451aa1e /home/ltratt/.cargo/registry/src/github.com-1ecc6299db9ec823/num-bigint-0.3.0/src/bigint.rs:135:19
    #9 0x5617219ce9eb in num_bigint::bigint::_$LT$impl$u20$core..ops..arith..Add$LT$$RF$num_bigint..bigint..BigInt$GT$$u20$for$u20$isize$GT$::add::hdc9938cedd2957b1 /home/ltratt/.cargo/registry/src/github.com-1ecc6299db9ec823/num-bigint-0.3.0/src/macros.rs:250:37
    #10 0x56172199b140 in _$LT$yksom..vm..objects..integers..Int$u20$as$u20$yksom..vm..objects..Obj$GT$::add::h7ffdbba834cb340f /home/ltratt/yksom/src/lib/vm/objects/integers.rs:419:32
    #11 0x5617219f7f68 in yksom::vm::val::Val::add::h5bc7a6fc4514f12c /home/ltratt/yksom/src/lib/vm/val.rs:347:9
    #12 0x561721989992 in yksom::vm::objects::integers::tests::test_bint::_$u7b$$u7b$closure$u7d$$u7d$::h0f6ad5d537e61520 /home/ltratt/yksom/src/lib/vm/objects/integers.rs:616:17
    #13 0x5617219af4c4 in core::ops::function::FnOnce::call_once::he65b3f39465d2bc0 /home/ltratt/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5
    #14 0x561721a60be9 in serial_test::serial_core::h5eafb4f0874e9389 /home/ltratt/.cargo/registry/src/github.com-1ecc6299db9ec823/serial_test-0.4.0/src/lib.rs:64:5
    #15 0x5617219a6cb8 in yksom::vm::objects::integers::tests::test_bint::h5a1132338fb8e338 /home/ltratt/yksom/src/lib/vm/objects/integers.rs:554:5
    #16 0x561721a41462 in core::ops::function::FnOnce::call_once::hcc2954d01bd82923 /rustc/31530e5d132ebcc3654baf2e5460599681520af0/library/core/src/ops/function.rs:227:5
    #17 0x561721a41462 in test::__rust_begin_short_backtrace::hcb8db2aeffacc321 /rustc/31530e5d132ebcc3654baf2e5460599681520af0/library/test/src/lib.rs:517:5

This might be expected behaviour (after all, we're not guaranteed to free everything), but I'm not sure, so it seems worth us considering in more detail. Even if it is a problem, I suspect it's more likely to be an rboehm issue, but since the bug manifests in yksom, we might as well start here.

ltratt commented 3 years ago

@jacob-hughes Does this issue still occur?

jacob-hughes commented 3 years ago

This has flagged up that rustgc doesn't build with the sanitizer flags. I need to work out why that is before I can check this.