1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-06 05:21:22 +03:00

UdpContext: check that pbuf_alloc doesn't return nullptr (#3354)

This commit is contained in:
Matthew Blythe 2017-09-22 02:56:27 -06:00 committed by Ivan Grokhotkov
parent 369edb616d
commit 13c1e8b293

View File

@ -246,6 +246,11 @@ public:
{
_reserve(_tx_buf_offset + size);
}
if (!_tx_buf_head || _tx_buf_head->tot_len < _tx_buf_offset + size)
{
DEBUGV("failed _reserve");
return 0;
}
size_t left_to_copy = size;
while(left_to_copy)
@ -271,6 +276,10 @@ public:
{
size_t data_size = _tx_buf_offset;
pbuf* tx_copy = pbuf_alloc(PBUF_TRANSPORT, data_size, PBUF_RAM);
if(!tx_copy){
DEBUGV("failed pbuf_alloc");
}
else{
uint8_t* dst = reinterpret_cast<uint8_t*>(tx_copy->payload);
for (pbuf* p = _tx_buf_head; p; p = p->next) {
size_t will_copy = (data_size < p->len) ? data_size : p->len;
@ -278,10 +287,14 @@ public:
dst += will_copy;
data_size -= will_copy;
}
}
pbuf_free(_tx_buf_head);
_tx_buf_head = 0;
_tx_buf_cur = 0;
_tx_buf_offset = 0;
if(!tx_copy){
return false;
}
if (!addr) {
@ -313,6 +326,10 @@ private:
if (!_tx_buf_head)
{
_tx_buf_head = pbuf_alloc(PBUF_TRANSPORT, pbuf_unit_size, PBUF_RAM);
if (!_tx_buf_head)
{
return;
}
_tx_buf_cur = _tx_buf_head;
_tx_buf_offset = 0;
}
@ -326,6 +343,10 @@ private:
while(grow_size)
{
pbuf* pb = pbuf_alloc(PBUF_TRANSPORT, pbuf_unit_size, PBUF_RAM);
if (!pb)
{
return;
}
pbuf_cat(_tx_buf_head, pb);
if (grow_size < pbuf_unit_size)
return;