diff --git a/src/core/pbuf.c b/src/core/pbuf.c index 25470863..d93e9eea 100644 --- a/src/core/pbuf.c +++ b/src/core/pbuf.c @@ -128,11 +128,10 @@ pbuf_free_ooseq(void) SYS_ARCH_SET(pbuf_free_ooseq_pending, 0); for (pcb = tcp_active_pcbs; NULL != pcb; pcb = pcb->next) { - if (NULL != pcb->ooseq) { + if (pcb->ooseq != NULL) { /** Free the ooseq pbufs of one PCB only */ LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_free_ooseq: freeing out-of-sequence pbufs\n")); - tcp_segs_free(pcb->ooseq); - pcb->ooseq = NULL; + tcp_free_ooseq(pcb); return; } } diff --git a/src/core/tcp.c b/src/core/tcp.c index 7ba5c396..52ec121d 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -1176,12 +1176,8 @@ tcp_slowtmr_start: #if TCP_QUEUE_OOSEQ if (pcb->ooseq != NULL && (tcp_ticks - pcb->tmr >= (u32_t)pcb->rto * TCP_OOSEQ_TIMEOUT)) { - tcp_segs_free(pcb->ooseq); - pcb->ooseq = NULL; LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_slowtmr: dropping OOSEQ queued data\n")); -#if LWIP_TCP_SACK_OUT - memset(pcb->rcv_sacks, 0, sizeof(pcb->rcv_sacks)); -#endif /* LWIP_TCP_SACK_OUT */ + tcp_free_ooseq(pcb); } #endif /* TCP_QUEUE_OOSEQ */ @@ -1888,12 +1884,8 @@ tcp_pcb_purge(struct tcp_pcb *pcb) #if TCP_QUEUE_OOSEQ if (pcb->ooseq != NULL) { LWIP_DEBUGF(TCP_DEBUG, ("tcp_pcb_purge: data left on ->ooseq\n")); + tcp_free_ooseq(pcb); } - tcp_segs_free(pcb->ooseq); - pcb->ooseq = NULL; -#if LWIP_TCP_SACK_OUT - memset(pcb->rcv_sacks, 0, sizeof(pcb->rcv_sacks)); -#endif /* LWIP_TCP_SACK_OUT */ #endif /* TCP_QUEUE_OOSEQ */ /* Stop the retransmission timer as it will expect data on unacked @@ -2113,6 +2105,19 @@ tcp_tcp_get_tcp_addrinfo(struct tcp_pcb *pcb, int local, ip_addr_t *addr, u16_t return ERR_VAL; } +/* Free all ooseq pbufs (and possibly reset SACK state) */ +void +tcp_free_ooseq(struct tcp_pcb *pcb) +{ + if (pcb->ooseq) { + tcp_segs_free(pcb->ooseq); + pcb->ooseq = NULL; +#if LWIP_TCP_SACK_OUT + memset(pcb->rcv_sacks, 0, sizeof(pcb->rcv_sacks)); +#endif /* LWIP_TCP_SACK_OUT */ + } +} + #if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG /** * Print a tcp header for debugging purposes. diff --git a/src/include/lwip/priv/tcp_priv.h b/src/include/lwip/priv/tcp_priv.h index 1670805c..b1d382f2 100644 --- a/src/include/lwip/priv/tcp_priv.h +++ b/src/include/lwip/priv/tcp_priv.h @@ -502,6 +502,10 @@ void tcp_timer_needed(void); void tcp_netif_ip_addr_changed(const ip_addr_t* old_addr, const ip_addr_t* new_addr); +#if TCP_QUEUE_OOSEQ +void tcp_free_ooseq(struct tcp_pcb *pcb); +#endif + #ifdef __cplusplus } #endif