Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6d64a3b

Browse filesBrowse files
WiFiUDP:parsePacket() Crashfix (espressif#7847)
* Update WiFiUdp.cpp * Update WiFiUdp.cpp
1 parent b8ea455 commit 6d64a3b
Copy full SHA for 6d64a3b

File tree

1 file changed

+7
-5
lines changed
Filter options

1 file changed

+7
-5
lines changed

‎libraries/WiFi/src/WiFiUdp.cpp

Copy file name to clipboardExpand all lines: libraries/WiFi/src/WiFiUdp.cpp
+7-5Lines changed: 7 additions & 5 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.