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

Small memory leak #17

Open
Thomas-Sparber opened this issue Aug 22, 2018 · 2 comments
Open

Small memory leak #17

Thomas-Sparber opened this issue Aug 22, 2018 · 2 comments

Comments

@Thomas-Sparber
Copy link

First of all: thank you so much for this great piece of software!

I found a small memory leak in the stl version of your library, it is in line 233:

this->threads[i].reset(new std::thread(f));

As you can see, a new thread is created with new but it is never deleted. Valgrind gives me the following message:

==5111== 1,216 bytes in 4 blocks are possibly lost in loss record 1,514 of 1,551
==5111== at 0x4C31B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5111== by 0x40134A6: allocate_dtv (dl-tls.c:286)
==5111== by 0x40134A6: _dl_allocate_tls (dl-tls.c:530)
==5111== by 0x5293227: allocate_stack (allocatestack.c:627)
==5111== by 0x5293227: pthread_create@@GLIBC_2.2.5 (pthread_create.c:644)
==5111== by 0x5AD4A18: std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_deletestd::thread::_State >, void (*)()) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.25)
==5111== by 0x255CB8: std::thread::threadctpl::thread_pool::set_thread(int)::{lambda()#1}&(ctpl::thread_pool::set_thread(int)::{lambda()#1}&) (thread:126)
==5111== by 0x253E17: ctpl::thread_pool::set_thread(int) (ctpl_stl.h:233)
==5111== by 0x2536C5: ctpl::thread_pool::resize(int) (ctpl_stl.h:102)
==5111== by 0x25349A: ctpl::thread_pool::thread_pool(int) (ctpl_stl.h:76)

I don't think that this error is very important and should be fixed ASAP, but I just wanted to let you know :-)

@s7726
Copy link

s7726 commented Sep 26, 2018

Looking further into this. The reset function of unique_ptr is passed the new object, according to the documentation it then takes over and handles the delete when appropriate.
Can you please post more info on the example you ran through valgrind?

@sigmasoldi3r
Copy link

@Thomas-Sparber Shouldn't the unique_ptr destroy the object? 🤔 Although valgrind is complaining... hmmm
https://en.cppreference.com/w/cpp/memory/unique_ptr/reset

If the old pointer was non-empty, deletes the previously managed object if(old_ptr) get_deleter()(old_ptr).

They say that 😮

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

3 participants