Skip to content

Commit

Permalink
Double free corruption fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
eminfedar committed Feb 21, 2022
1 parent b3a744b commit a17b3e1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions async-sockets/include/tcpserver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class TCPServer : public BaseSocket
if (!server->isClosed && newSock >= 0)
{
TCPSocket *newSocket = new TCPSocket(onError, newSock);
newSocket->deleteAfterClosed = true;
newSocket->setAddressStruct(newSocketInfo);

server->onNewConnection(newSocket);
Expand Down
4 changes: 3 additions & 1 deletion async-sockets/include/tcpsocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class TCPSocket : public BaseSocket
void setAddressStruct(sockaddr_in addr) {this->address = addr;}
sockaddr_in getAddressStruct() const {return this->address;}

bool deleteAfterClosed = false;

private:
static void Receive(TCPSocket *socket)
{
Expand All @@ -111,7 +113,7 @@ class TCPSocket : public BaseSocket
if(socket->onSocketClosed)
socket->onSocketClosed(errno);

if (socket != nullptr)
if (socket->deleteAfterClosed && socket != nullptr)
delete socket;
}

Expand Down

0 comments on commit a17b3e1

Please sign in to comment.