Skip to content

Commit 52fc349

Browse files
committed
Fix memory leak
1 parent c842977 commit 52fc349

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

libraries/WiFi/src/WiFiUdp.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ extern WiFiClass WiFi;
77
#endif
88

99
arduino::WiFiUDP::WiFiUDP() {
10-
_packet_buffer = (uint8_t*)malloc(WIFI_UDP_BUFFER_SIZE);
10+
_packet_buffer = new uint8_t[WIFI_UDP_BUFFER_SIZE];
1111
_current_packet = NULL;
1212
_current_packet_size = 0;
13-
// if this malloc fails then ::begin will fail
13+
// if this allocation fails then ::begin will fail
1414
}
1515

1616
uint8_t arduino::WiFiUDP::begin(uint16_t port) {
@@ -33,6 +33,7 @@ uint8_t arduino::WiFiUDP::begin(uint16_t port) {
3333

3434
void arduino::WiFiUDP::stop() {
3535
_socket.close();
36+
delete[] _packet_buffer;
3637
}
3738

3839
int arduino::WiFiUDP::beginPacket(IPAddress ip, uint16_t port) {

0 commit comments

Comments
 (0)