From 149bb3680519bb300acf7e6725cc2839957f1eaf Mon Sep 17 00:00:00 2001 From: sg Date: Thu, 17 Mar 2016 21:49:01 +0100 Subject: [PATCH] fixed bug #47448 (netconn/socket leak if RST is received during close) --- CHANGELOG | 3 +++ src/api/api_msg.c | 12 +++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 9d087324..936edfe8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -302,6 +302,9 @@ HISTORY ++ Bugfixes: + 2013-03-17: Simon Goldschmidt + * api_msg.c: fixed bug #47448 (netconn/socket leak if RST is received during close) + 2013-03-17: Joel Cunningham * api_msg.c: don't fail closing a socket/netconn when failing to allocate the FIN segment; blocking the calling thread for a while is better than risking diff --git a/src/api/api_msg.c b/src/api/api_msg.c index fd5594bb..93b12a84 100644 --- a/src/api/api_msg.c +++ b/src/api/api_msg.c @@ -378,13 +378,19 @@ err_tcp(void *arg, err_t err) conn->pcb.tcp = NULL; - /* no check since this is always fatal! */ - SYS_ARCH_SET(conn->last_err, err); - /* reset conn->state now before waking up other threads */ old_state = conn->state; conn->state = NETCONN_NONE; + if (old_state == NETCONN_CLOSE) { + /* RST during close: let close return success & dealloc the netconn */ + err = ERR_OK; + NETCONN_SET_SAFE_ERR(conn, ERR_OK); + } else { + /* no check since this is always fatal! */ + SYS_ARCH_SET(conn->last_err, err); + } + /* @todo: the type of NETCONN_EVT created should depend on 'old_state' */ /* Notify the user layer about a connection error. Used to signal select. */