From ad7596c5740e4bfc50d48dc2815fc1737cfb319d Mon Sep 17 00:00:00 2001 From: David McCurley <44048235+mrengineer7777@users.noreply.github.com> Date: Tue, 11 Apr 2023 08:42:04 -0500 Subject: [PATCH] WiFiUDF Low memory fix Fixed library crash on low memory where `new char[1460];` throws an exception. `malloc` is a safe drop in replacement. --- libraries/WiFi/src/WiFiUdp.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/WiFi/src/WiFiUdp.cpp b/libraries/WiFi/src/WiFiUdp.cpp index 556f9a8afcc..e3b911937f9 100644 --- a/libraries/WiFi/src/WiFiUdp.cpp +++ b/libraries/WiFi/src/WiFiUdp.cpp @@ -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; @@ -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; @@ -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;