Ok, I've found a solution - I have modified tcp_clos.c - I've changed TCP_Close_TCB, adding the following to the end of that function:
/*
* Close any sockets opened by accept
*/
prev_req = NULL;
req = tcp_cfg->OPENS;
while( req != NULL )
{
if( ( req->TCB_PTR == tcb ) && ( ( ( SOCKET_STRUCT_PTR )req->SOCKET )->TCB_PTR == NULL ) ) {
void * toBeFreed = req;
SOCK_Free_sock_struct( ( SOCKET_STRUCT_PTR )req->SOCKET );
// Just in case any thread is blocked waiting for this, send req complete.
RTCSCMD_complete( req, RTCSERR_TCP_CONN_RLSD );
// Remove the request from the open requests list
if( prev_req != NULL ) {
prev_req->NEXT = req->NEXT;
}
else {
tcp_cfg->OPENS = req->NEXT;
}
// Move on to the next request
req = req->NEXT;
// Free the old request.
_mem_free( toBeFreed );
}
else {
prev_req = req;
req = req->NEXT;
}
}
This looks for any Open Requests with the same TCB pointer in the request (the TCB of the listening socket), and where the socket has a NULL TCB pointer, and frees the socket.
This does not free any sockets that were spawned by the listening socket that have connected (the socket TCB wouldn't be NULL in that case).