mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-11-18 20:10:53 +00:00
Fixed a memory leak when only a part of a PBUF_POOL chain could be allocated.
This commit is contained in:
parent
9ed2b7e03c
commit
326b8ff728
@ -251,6 +251,8 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
|
||||
p->len = length > PBUF_POOL_BUFSIZE - offset? PBUF_POOL_BUFSIZE - offset: length;
|
||||
/* set pbuf type */
|
||||
p->flags = PBUF_FLAG_POOL;
|
||||
/* set reference count (needed here in case we fail) */
|
||||
p->ref = 1;
|
||||
|
||||
/* now allocate the tail of the pbuf chain */
|
||||
|
||||
@ -266,11 +268,12 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
|
||||
#ifdef PBUF_STATS
|
||||
++lwip_stats.pbuf.err;
|
||||
#endif /* PBUF_STATS */
|
||||
/* bail out unsuccesfully */
|
||||
/* free chain so far allocated */
|
||||
pbuf_free(p);
|
||||
/* bail out unsuccesfully */
|
||||
return NULL;
|
||||
}
|
||||
/*q->next = NULL;*/
|
||||
q->next = NULL;
|
||||
/* make previous pbuf point to this pbuf */
|
||||
r->next = q;
|
||||
/* set total length of this pbuf and next in chain */
|
||||
@ -326,6 +329,7 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
|
||||
LWIP_ASSERT("pbuf_alloc: erroneous flag", 0);
|
||||
return NULL;
|
||||
}
|
||||
/* set reference count */
|
||||
p->ref = 1;
|
||||
return p;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user