Skip to content

Commit

Permalink
Fix memory leak by removing tcpsocket after closing
Browse files Browse the repository at this point in the history
  • Loading branch information
eminfedar committed Sep 28, 2021
1 parent ac946e4 commit fd075b9
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions async-sockets/include/tcpsocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ class TCPSocket : public BaseSocket
socket->Close();
if(socket->onSocketClosed)
socket->onSocketClosed(errno);

if (socket != nullptr)

This comment has been minimized.

Copy link
@omari

omari Feb 19, 2022

deletting "socket" here is not good,
it is created outside of the library, and it must be deleted outside.

as a test case, i have created socket as a globale static variable:
TcpSocket socket;

then this line throw an exception.

This comment has been minimized.

Copy link
@eminfedar

eminfedar Feb 19, 2022

Author Owner

You are right for client. This saved the "server-side", because after a tcp client disconnected from server, this deleted the client.

Maybe we should delete the client on server side code, not here. 👍🏻

Or a simple boolean flag if this socket should be deleted when closed.

delete socket;
}

void setTimeout(int seconds)
Expand Down

0 comments on commit fd075b9

Please sign in to comment.