Skip to content

Commit 6d64a3b

Browse files
WiFiUDP:parsePacket() Crashfix (#7847)
* Update WiFiUdp.cpp * Update WiFiUdp.cpp
1 parent b8ea455 commit 6d64a3b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

libraries/WiFi/src/WiFiUdp.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
License along with this library; if not, write to the Free Software
1717
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1818
*/
19+
1920
#include "WiFiUdp.h"
21+
#include <new> //std::nothrow
2022
#include <lwip/sockets.h>
2123
#include <lwip/netdb.h>
2224
#include <errno.h>
@@ -207,12 +209,12 @@ int WiFiUDP::parsePacket(){
207209
return 0;
208210
struct sockaddr_in si_other;
209211
int slen = sizeof(si_other) , len;
210-
char * buf = new char[1460];
211-
if(!buf){
212+
char *buf = (char *)malloc(1460);
213+
if(!buf) {
212214
return 0;
213215
}
214216
if ((len = recvfrom(udp_server, buf, 1460, MSG_DONTWAIT, (struct sockaddr *) &si_other, (socklen_t *)&slen)) == -1){
215-
delete[] buf;
217+
free(buf);
216218
if(errno == EWOULDBLOCK){
217219
return 0;
218220
}
@@ -222,10 +224,10 @@ int WiFiUDP::parsePacket(){
222224
remote_ip = IPAddress(si_other.sin_addr.s_addr);
223225
remote_port = ntohs(si_other.sin_port);
224226
if (len > 0) {
225-
rx_buffer = new cbuf(len);
227+
rx_buffer = new(std::nothrow) cbuf(len);
226228
rx_buffer->write(buf, len);
227229
}
228-
delete[] buf;
230+
free(buf);
229231
return len;
230232
}
231233

0 commit comments

Comments
 (0)