From 4022a19cbcf6b203db047a830331684c89ecf568 Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Mon, 3 Feb 2020 22:13:07 +0100 Subject: [PATCH] altcp: fix altcp_tcp_close for LISTEN pcb See bug #55219 Signed-off-by: Simon Goldschmidt (cherry picked from commit 064d816ea1f526a2f9b4d48eb8b195d1f7e91068) --- src/core/altcp_tcp.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/core/altcp_tcp.c b/src/core/altcp_tcp.c index 867d2b44..1869e2a3 100644 --- a/src/core/altcp_tcp.c +++ b/src/core/altcp_tcp.c @@ -161,21 +161,25 @@ static void altcp_tcp_remove_callbacks(struct tcp_pcb *tpcb) { tcp_arg(tpcb, NULL); - tcp_recv(tpcb, NULL); - tcp_sent(tpcb, NULL); - tcp_err(tpcb, NULL); - tcp_poll(tpcb, NULL, tpcb->pollinterval); + if (tpcb->state != LISTEN) { + tcp_recv(tpcb, NULL); + tcp_sent(tpcb, NULL); + tcp_err(tpcb, NULL); + tcp_poll(tpcb, NULL, tpcb->pollinterval); + } } static void altcp_tcp_setup_callbacks(struct altcp_pcb *conn, struct tcp_pcb *tpcb) { tcp_arg(tpcb, conn); - tcp_recv(tpcb, altcp_tcp_recv); - tcp_sent(tpcb, altcp_tcp_sent); - tcp_err(tpcb, altcp_tcp_err); - /* tcp_poll is set when interval is set by application */ - /* listen is set totally different :-) */ + /* this might be called for LISTN when close fails... */ + if (tpcb->state != LISTEN) { + tcp_recv(tpcb, altcp_tcp_recv); + tcp_sent(tpcb, altcp_tcp_sent); + tcp_err(tpcb, altcp_tcp_err); + /* tcp_poll is set when interval is set by application */ + } } static void