Skip to content

Commit

Permalink
WiFiUDF Low memory fix (#8065)
Browse files Browse the repository at this point in the history
Fixed library crash on low memory where `new char[1460];` throws an exception.  `malloc` is a safe drop in replacement.
  • Loading branch information
mrengineer7777 authored and me-no-dev committed Sep 4, 2023
1 parent 5ebe01f commit 3bf1e07
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions libraries/WiFi/src/WiFiUdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ uint8_t WiFiUDP::begin(IPAddress address, uint16_t port){

server_port = port;

tx_buffer = new char[1460];
tx_buffer = (char *)malloc(1460);
if(!tx_buffer){
log_e("could not create tx buffer: %d", errno);
return 0;
Expand Down Expand Up @@ -100,7 +100,7 @@ uint8_t WiFiUDP::beginMulticast(IPAddress a, uint16_t p){

void WiFiUDP::stop(){
if(tx_buffer){
delete[] tx_buffer;
free(tx_buffer);
tx_buffer = NULL;
}
tx_buffer_len = 0;
Expand Down Expand Up @@ -136,7 +136,7 @@ int WiFiUDP::beginPacket(){

// allocate tx_buffer if is necessary
if(!tx_buffer){
tx_buffer = new char[1460];
tx_buffer = (char *)malloc(1460);
if(!tx_buffer){
log_e("could not create tx buffer: %d", errno);
return 0;
Expand Down

0 comments on commit 3bf1e07

Please sign in to comment.