Browse Source

Fixed memory leak

Joseph Henry 9 years ago
parent
commit
a73638b214
1 changed files with 11 additions and 11 deletions
  1. 11 11
      netcon/NetconEthernetTap.cpp

+ 11 - 11
netcon/NetconEthernetTap.cpp

@@ -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
-		removeConnection(conn);
-	if(!conn->pcb)
-		return;
-	if(conn->pcb->state == SYN_SENT || conn->pcb->state == CLOSE_WAIT) {
-		dwr(MSG_DEBUG," closeConnection(): invalid PCB state for this operation. ignoring.\n");
-		return;
-	}	
-	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");
+	if(conn->pcb) {
+		if(conn->pcb->state == SYN_SENT || conn->pcb->state == CLOSE_WAIT) {
+			dwr(MSG_DEBUG," closeConnection(): invalid PCB state for this operation. ignoring.\n");
+			return;
+		}	
+		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));