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

Memory leaks #2

Open
aminya opened this issue Sep 30, 2021 · 5 comments
Open

Memory leaks #2

aminya opened this issue Sep 30, 2021 · 5 comments

Comments

@aminya
Copy link

aminya commented Sep 30, 2021

I tried this package with RUSTFLAGS="-Z sanitizer=address" cargo build, and there are a lot of memory leaks in my code.

==528==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 40 byte(s) in 1 object(s) allocated from:
    #0 0x5568f7228c4d in malloc /rustc/llvm/src/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:129:3
    #1 0x5568f7808c0b in alloc::alloc::alloc::h3bced346ddf221f1 /rustc/11491938f80988c7261a1179cf71a25c379c8783/library/alloc/src/alloc.rs:86:14
    #2 0x5568f7808eb7 in alloc::alloc::Global::alloc_impl::hcd9d03062a49d96b /rustc/11491938f80988c7261a1179cf71a25c379c8783/library/alloc/src/alloc.rs:166:73
    #3 0x5568f7809880 in _$LT$alloc..alloc..Global$u20$as$u20$core..alloc..Allocator$GT$::allocate::h80dd74306609a6fd /rustc/11491938f80988c7261a1179cf71a25c379c8783/library/alloc/src/alloc.rs:226:9
    #4 0x5568f7808916 in alloc::alloc::exchange_malloc::h53677898fe10293d /rustc/11491938f80988c7261a1179cf71a25c379c8783/library/alloc/src/alloc.rs:315:11
    #5 0x5568f78062ff in alloc::boxed::Box$LT$T$GT$::new::h604a175c798a14cc /rustc/11491938f80988c7261a1179cf71a25c379c8783/library/alloc/src/boxed.rs:191:9
    #6 0x5568f78062ff in unrolled_linked_list::UnrolledLinkedList$LT$T$GT$::push::h8b201f923d055933 /home/aminya/.cargo/registry/src/github.com-1ecc6299db9ec823/unrolled-linked-list-1.0.1/src/lib.rs:129:32

It points to this location of code

let mut node = Box::new(Node::new());

@besok
Copy link
Owner

besok commented Oct 3, 2021

Hey. Thanks. I will check this out

@besok
Copy link
Owner

besok commented Oct 5, 2021

So I have checked the repo with a sanitiser. In a default mode, it gives a lot of memory leaks from tests that is why I created a binary and tested it with it.

It displayed much fewer memory leaks but some amount preserved.
I analyzed it and hasten to say they are fairly safe.

The vast part leads into the system vec implementation where I can do nothing to detect.
The residual truly points out to the part where the new node is instantiated but then the node is deliberately leaked - code

@aminya
Copy link
Author

aminya commented Oct 5, 2021

When I use std::collections::LinkedList, I don't get any memory leaks errors. I think there should be a way to avoid those.

My suggestion for tracking this is to move the tests into a simple main.rs file. When you use cargo test, the code runs in parallel, and there are other things that may trigger false positives.

@besok
Copy link
Owner

besok commented Oct 6, 2021

yes, absolutely.
I will try to move tests into main.rs and will check again.
But I am afraid, some of the leaks will be there since I am deliberately creating them like that:
self.head = Some(Box::leak(first_node).into())

But, that is a safe leak since it remains inside and not exposed.

Nevertheless, I will play with it more diligently.

@besok
Copy link
Owner

besok commented Nov 4, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants