From 2a4dd0dc7b7fa3437f6a8125e25091e8b369c71a Mon Sep 17 00:00:00 2001 From: goldsimon Date: Sun, 4 Feb 2018 14:00:23 +0100 Subject: [PATCH] altcp: priority-based pcb/conn allocation required altcp_tcp_new_ip_type: allocate the tcp pcb first to invoke the priority handling code if we're out of pcbs --- src/core/altcp_tcp.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/core/altcp_tcp.c b/src/core/altcp_tcp.c index 72be8153..ebb0adf5 100644 --- a/src/core/altcp_tcp.c +++ b/src/core/altcp_tcp.c @@ -185,18 +185,20 @@ altcp_tcp_setup(struct altcp_pcb *conn, struct tcp_pcb *tpcb) struct altcp_pcb * altcp_tcp_new_ip_type(u8_t ip_type) { - struct altcp_pcb *ret = altcp_alloc(); - if (ret != NULL) { - struct tcp_pcb *tpcb = tcp_new_ip_type(ip_type); - if (tpcb != NULL) { + /* Allocate the tcp pcb first to invoke the priority handling code + if we're out of pcbs */ + struct tcp_pcb *tpcb = tcp_new_ip_type(ip_type); + if (tpcb != NULL) { + struct altcp_pcb *ret = altcp_alloc(); + if (ret != NULL) { altcp_tcp_setup(ret, tpcb); + return ret; } else { - /* tcp_pcb allocation failed -> free the altcp_pcb too */ - altcp_free(ret); - ret = NULL; + /* altcp_pcb allocation failed -> free the tcp_pcb too */ + tcp_close(tpcb); } } - return ret; + return NULL; } struct altcp_pcb *