16
16
License along with this library; if not, write to the Free Software
17
17
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
18
*/
19
+
19
20
#include " WiFiUdp.h"
21
+ #include < new> // std::nothrow
20
22
#include < lwip/sockets.h>
21
23
#include < lwip/netdb.h>
22
24
#include < errno.h>
@@ -207,12 +209,12 @@ int WiFiUDP::parsePacket(){
207
209
return 0 ;
208
210
struct sockaddr_in si_other;
209
211
int slen = sizeof (si_other) , len;
210
- char *buf = new char [ 1460 ] ;
211
- if (!buf){
212
+ char *buf = ( char *) malloc ( 1460 ) ;
213
+ if (!buf){
212
214
return 0 ;
213
215
}
214
216
if ((len = recvfrom (udp_server, buf, 1460 , MSG_DONTWAIT, (struct sockaddr *) &si_other, (socklen_t *)&slen)) == -1 ){
215
- delete[] buf;
217
+ free ( buf) ;
216
218
if (errno == EWOULDBLOCK){
217
219
return 0 ;
218
220
}
@@ -222,10 +224,10 @@ int WiFiUDP::parsePacket(){
222
224
remote_ip = IPAddress (si_other.sin_addr .s_addr );
223
225
remote_port = ntohs (si_other.sin_port );
224
226
if (len > 0 ) {
225
- rx_buffer = new cbuf (len);
227
+ rx_buffer = new (std::nothrow) cbuf (len);
226
228
rx_buffer->write (buf, len);
227
229
}
228
- delete[] buf;
230
+ free ( buf) ;
229
231
return len;
230
232
}
231
233
0 commit comments