From 6d64a3b6342ede7b073a7d98273965b890af8abc Mon Sep 17 00:00:00 2001 From: David McCurley <44048235+mrengineer7777@users.noreply.github.com> Date: Mon, 20 Feb 2023 05:30:40 -0600 Subject: [PATCH] WiFiUDP:parsePacket() Crashfix (#7847) * Update WiFiUdp.cpp * Update WiFiUdp.cpp --- libraries/WiFi/src/WiFiUdp.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libraries/WiFi/src/WiFiUdp.cpp b/libraries/WiFi/src/WiFiUdp.cpp index 476b5a4a8..556f9a8af 100644 --- a/libraries/WiFi/src/WiFiUdp.cpp +++ b/libraries/WiFi/src/WiFiUdp.cpp @@ -16,7 +16,9 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + #include "WiFiUdp.h" +#include //std::nothrow #include #include #include @@ -207,12 +209,12 @@ int WiFiUDP::parsePacket(){ return 0; struct sockaddr_in si_other; int slen = sizeof(si_other) , len; - char * buf = new char[1460]; - if(!buf){ + char *buf = (char *)malloc(1460); + if(!buf) { return 0; } if ((len = recvfrom(udp_server, buf, 1460, MSG_DONTWAIT, (struct sockaddr *) &si_other, (socklen_t *)&slen)) == -1){ - delete[] buf; + free(buf); if(errno == EWOULDBLOCK){ return 0; } @@ -222,10 +224,10 @@ int WiFiUDP::parsePacket(){ remote_ip = IPAddress(si_other.sin_addr.s_addr); remote_port = ntohs(si_other.sin_port); if (len > 0) { - rx_buffer = new cbuf(len); + rx_buffer = new(std::nothrow) cbuf(len); rx_buffer->write(buf, len); } - delete[] buf; + free(buf); return len; } -- GitLab