From a13c488e522015a08960023a4fea696841ed1a4b Mon Sep 17 00:00:00 2001 From: goldsimon Date: Mon, 28 Aug 2017 21:59:05 +0200 Subject: [PATCH] Fix bug #51687 (tcp_close(): is it OK to return ERR_MEM if TF_CLOSEPEND is set?) (cherry picked from commit 1d4ca0bff66e6f1136291f387293eee678d1f2fe) # Conflicts: # src/core/tcp.c --- src/core/tcp.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/core/tcp.c b/src/core/tcp.c index 17b681e5..b5144d2f 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -370,6 +370,12 @@ tcp_close_shutdown_fin(struct tcp_pcb *pcb) } else if (err == ERR_MEM) { /* Mark this pcb for closing. Closing is retried from tcp_tmr. */ pcb->flags |= TF_CLOSEPEND; + /* We have to return ERR_OK from here to indicate to the callers that this + pcb should not be used any more as it will be freed soon via tcp_tmr. + This is OK here since sending FIN does not guarantee a time frime for + actually freeing the pcb, either (it is left in closure states for + remote ACK or timeout) */ + return ERR_OK; } return err; } @@ -407,8 +413,8 @@ tcp_close(struct tcp_pcb *pcb) * @ingroup tcp_raw * Causes all or part of a full-duplex connection of this PCB to be shut down. * This doesn't deallocate the PCB unless shutting down both sides! - * Shutting down both sides is the same as calling tcp_close, so if it succeds, - * the PCB should not be referenced any more. + * Shutting down both sides is the same as calling tcp_close, so if it succeds + * (i.e. returns ER_OK), the PCB must not be referenced any more! * * @param pcb PCB to shutdown * @param shut_rx shut down receive side if this is != 0