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 leak #26

Closed
ArdxWe opened this issue Mar 19, 2022 · 3 comments
Closed

memory leak #26

ArdxWe opened this issue Mar 19, 2022 · 3 comments

Comments

@ArdxWe
Copy link

ArdxWe commented Mar 19, 2022

$ valgrind -q --leak-check=full ./tcp-client
Connected to the server successfully.
Message from the Server: OK!
123
Message from the Server: OK!
123
Message from the Server: OK!
123
Message from the Server: OK!
123
Message from the Server: OK!
123
Message from the Server: OK!
123
Message from the Server: OK!
^C==9540== 288 bytes in 1 blocks are possibly lost in loss record 2 of 2
==9540==    at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==9540==    by 0x40149CA: allocate_dtv (dl-tls.c:286)
==9540==    by 0x40149CA: _dl_allocate_tls (dl-tls.c:532)
==9540==    by 0x4860322: allocate_stack (allocatestack.c:622)
==9540==    by 0x4860322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660)
==9540==    by 0x49510A8: std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)()) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.28)
==9540==    by 0x10CE6E: std::thread::thread<void (&)(TCPSocket*), TCPSocket*, void>(void (&)(TCPSocket*), TCPSocket*&&) (in /home/ardxwe/github/async-sockets-cpp/examples/tcp-client)
==9540==    by 0x10C788: TCPSocket::Listen() (in /home/ardxwe/github/async-sockets-cpp/examples/tcp-client)
==9540==    by 0x10C6F9: TCPSocket::Connect(unsigned int, unsigned short, std::function<void ()>, std::function<void (int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)>) (in /home/ardxwe/github/async-sockets-cpp/examples/tcp-client)
==9540==    by 0x10C525: TCPSocket::Connect(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned short, std::function<void ()>, std::function<void (int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)>) (in /home/ardxwe/github/async-sockets-cpp/examples/tcp-client)
==9540==    by 0x10A9AF: main (in /home/ardxwe/github/async-sockets-cpp/examples/tcp-client)
==9540==

I think we shouldn't use std::thread.detach.

@eminfedar
Copy link
Owner

I'm open to suggestions.

@ChristianGabs
Copy link

Base by what I can see threads are detashed

Is this an issue fixed or ?

@eminfedar
Copy link
Owner

The detached threads end when function finish. So the return of recv() not bigger than 0 makes thread function finish and clear itself. Yes valgrind shows a leak because of the detached thread but I see no problem here.

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