Skip to content

Commit 483bebf

Browse files
WiFiUDF Low memory fix (#8065)
Fixed library crash on low memory where `new char[1460];` throws an exception. `malloc` is a safe drop in replacement.
1 parent 788a4ca commit 483bebf

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

libraries/WiFi/src/WiFiUdp.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ uint8_t WiFiUDP::begin(IPAddress address, uint16_t port){
4444

4545
server_port = port;
4646

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

101101
void WiFiUDP::stop(){
102102
if(tx_buffer){
103-
delete[] tx_buffer;
103+
free(tx_buffer);
104104
tx_buffer = NULL;
105105
}
106106
tx_buffer_len = 0;
@@ -136,7 +136,7 @@ int WiFiUDP::beginPacket(){
136136

137137
// allocate tx_buffer if is necessary
138138
if(!tx_buffer){
139-
tx_buffer = new char[1460];
139+
tx_buffer = (char *)malloc(1460);
140140
if(!tx_buffer){
141141
log_e("could not create tx buffer: %d", errno);
142142
return 0;

0 commit comments

Comments
 (0)