mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-12-26 12:13:47 +00:00
Fix memory leaks.
When pbufs are chained, the second pbuf must be freed, if no higher level application refers to it any longer.
This commit is contained in:
parent
18a215e6a8
commit
50f47f18c1
@ -947,8 +947,9 @@ tcp_receive(struct tcp_pcb *pcb)
|
|||||||
/* Chain this pbuf onto the pbuf that we will pass to
|
/* Chain this pbuf onto the pbuf that we will pass to
|
||||||
the application. */
|
the application. */
|
||||||
if(recv_data) {
|
if(recv_data) {
|
||||||
pbuf_chain(recv_data, cseg->p);
|
pbuf_chain(recv_data, cseg->p);
|
||||||
} else {
|
pbuf_free(cseg->p);
|
||||||
|
} else {
|
||||||
recv_data = cseg->p;
|
recv_data = cseg->p;
|
||||||
}
|
}
|
||||||
cseg->p = NULL;
|
cseg->p = NULL;
|
||||||
|
@ -213,6 +213,7 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
|
|||||||
|
|
||||||
/* Chain the headers and data pbufs together. */
|
/* Chain the headers and data pbufs together. */
|
||||||
pbuf_chain(seg->p, p);
|
pbuf_chain(seg->p, p);
|
||||||
|
pbuf_free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now that there are more segments queued, we check again if the
|
/* Now that there are more segments queued, we check again if the
|
||||||
@ -287,6 +288,10 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
|
|||||||
/* Remove TCP header from first segment. */
|
/* Remove TCP header from first segment. */
|
||||||
pbuf_header(queue->p, -TCP_HLEN);
|
pbuf_header(queue->p, -TCP_HLEN);
|
||||||
pbuf_chain(useg->p, queue->p);
|
pbuf_chain(useg->p, queue->p);
|
||||||
|
/* Free buffer which was merged. Note that the previous pbuf_chain call
|
||||||
|
* will have incremented the ref count, so here the ref count will still
|
||||||
|
* be 1 for the 1 pointer still being used on this buffer. */
|
||||||
|
pbuf_free(queue->p);
|
||||||
useg->len += queue->len;
|
useg->len += queue->len;
|
||||||
useg->next = queue->next;
|
useg->next = queue->next;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user