From eb69032773b23ca1c0863527c9c1d10d407a859e Mon Sep 17 00:00:00 2001 From: kieranm Date: Fri, 23 Jul 2004 13:07:00 +0000 Subject: [PATCH] Kieran Mansley - kjm25@cam.ac.uk - 23rd July 2004 Now handle CLOSED state in tcp_close() explicitely, and free the pcb. This is for the case that a pcb has been allocated but never used (so is in the default "CLOSED" state) and needs to be freed. --- src/core/tcp.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/core/tcp.c b/src/core/tcp.c index 5ca2a8fa..ed8758f5 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -122,6 +122,18 @@ tcp_close(struct tcp_pcb *pcb) LWIP_DEBUGF(TCP_DEBUG, ("\n")); #endif /* TCP_DEBUG */ switch (pcb->state) { + case CLOSED: + /* Closing a pcb in the CLOSED state might seem erroneous, + * however, it is in this state once allocated and as yet unused + * and the user needs some way to free it should the need arise. + * Calling tcp_close() with a pcb that has already been closed, (i.e. twice) + * or for a pcb that has been used and then entered the CLOSED state + * is erroneous, but this should never happen as the pcb has in those cases + * been freed, and so any remaining handles are bogus. */ + err = ERR_OK; + memp_free(MEMP_TCP_PCB, pcb); + pcb = NULL; + break; case LISTEN: err = ERR_OK; tcp_pcb_remove((struct tcp_pcb **)&tcp_listen_pcbs.pcbs, pcb);