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.
This commit is contained in:
goldsimon 2017-11-17 22:04:52 +01:00
parent 0853d1e7d1
commit 8c6884b2db

View File

@ -329,18 +329,12 @@ tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data)
tcp_pcb_purge(pcb); tcp_pcb_purge(pcb);
TCP_RMV_ACTIVE(pcb); TCP_RMV_ACTIVE(pcb);
if (pcb->state == ESTABLISHED) { /* Deallocate the pcb since we already sent a RST for it */
/* move to TIME_WAIT since we close actively */ if (tcp_input_pcb == pcb) {
pcb->state = TIME_WAIT; /* prevent using a deallocated pcb: free it from tcp_input later */
TCP_REG(&tcp_tw_pcbs, pcb); tcp_trigger_input_pcb_close();
} else { } else {
/* CLOSE_WAIT: deallocate the pcb since we already sent a RST for it */ memp_free(MEMP_TCP_PCB, pcb);
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);
}
} }
return ERR_OK; return ERR_OK;
} }