From 8c6884b2db37a8344a8fb93c858588912085f687 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Fri, 17 Nov 2017 22:04:52 +0100 Subject: [PATCH] tcp_close_shutdown: always deallocate the pcb if there is unread data on close (see bug #52403) We preserved the TIME_WAIT handling before, but it seems this is not correct: we want to issue a RST later again if someone wants to talk to this port. With TIME_WAIT, this might not always the case. --- src/core/tcp.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/core/tcp.c b/src/core/tcp.c index dde0632a..472737ff 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -329,18 +329,12 @@ tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data) tcp_pcb_purge(pcb); TCP_RMV_ACTIVE(pcb); - if (pcb->state == ESTABLISHED) { - /* move to TIME_WAIT since we close actively */ - pcb->state = TIME_WAIT; - TCP_REG(&tcp_tw_pcbs, pcb); + /* Deallocate the pcb since we already sent a RST for it */ + if (tcp_input_pcb == pcb) { + /* prevent using a deallocated pcb: free it from tcp_input later */ + tcp_trigger_input_pcb_close(); } else { - /* CLOSE_WAIT: deallocate the pcb since we already sent a RST for it */ - if (tcp_input_pcb == pcb) { - /* prevent using a deallocated pcb: free it from tcp_input later */ - tcp_trigger_input_pcb_close(); - } else { - memp_free(MEMP_TCP_PCB, pcb); - } + memp_free(MEMP_TCP_PCB, pcb); } return ERR_OK; }