Fixed memory leak

This commit is contained in:
Joseph Henry 2016-01-17 14:32:34 -08:00
parent 58ebfdffcb
commit a73638b214

View file

@ -420,6 +420,7 @@ void NetconEthernetTap::removeConnection(TcpConnection *conn)
for(size_t i=0;i<_TcpConnections.size();++i) { for(size_t i=0;i<_TcpConnections.size();++i) {
if(_TcpConnections[i] == conn){ if(_TcpConnections[i] == conn){
_TcpConnections.erase(_TcpConnections.begin() + i); _TcpConnections.erase(_TcpConnections.begin() + i);
delete conn;
return; return;
} }
} }
@ -435,18 +436,17 @@ void NetconEthernetTap::closeConnection(PhySocket *sock)
TcpConnection *conn = getConnection(sock); TcpConnection *conn = getConnection(sock);
if(!conn) if(!conn)
return; return;
else if(conn->pcb) {
removeConnection(conn); if(conn->pcb->state == SYN_SENT || conn->pcb->state == CLOSE_WAIT) {
if(!conn->pcb) dwr(MSG_DEBUG," closeConnection(): invalid PCB state for this operation. ignoring.\n");
return; return;
if(conn->pcb->state == SYN_SENT || conn->pcb->state == CLOSE_WAIT) { }
dwr(MSG_DEBUG," closeConnection(): invalid PCB state for this operation. ignoring.\n"); dwr(MSG_DEBUG," closeConnection(): PCB->state = %d\n", conn->pcb->state);
return; if(lwipstack->_tcp_close(conn->pcb) != ERR_OK) {
} dwr(MSG_ERROR," closeConnection(): error while calling tcp_close()\n");
dwr(MSG_DEBUG," closeConnection(): PCB->state = %d\n", conn->pcb->state); }
if(lwipstack->_tcp_close(conn->pcb) != ERR_OK) {
dwr(MSG_ERROR," closeConnection(): error while calling tcp_close()\n");
} }
removeConnection(conn);
if(!sock) if(!sock)
return; return;
close(_phy.getDescriptor(sock)); close(_phy.getDescriptor(sock));