Skip to content

Commit c171117

Browse files
committed
Add destructor for memory cleanup
1 parent 8456368 commit c171117

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

libraries/WiFi/src/WiFiUdp.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ arduino::WiFiUDP::WiFiUDP() {
1313
// if this allocation fails then ::begin will fail
1414
}
1515

16+
arduino::WiFiUDP::~WiFiUDP() {
17+
delete[] _packet_buffer;
18+
}
19+
1620
uint8_t arduino::WiFiUDP::begin(uint16_t port) {
1721
// success = 1, fail = 0
1822

@@ -36,8 +40,7 @@ uint8_t arduino::WiFiUDP::begin(uint16_t port) {
3640
}
3741

3842
void arduino::WiFiUDP::stop() {
39-
_socket.close();
40-
delete[] _packet_buffer;
43+
_socket.close();
4144
}
4245

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

libraries/WiFi/src/WiFiUdp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class WiFiUDP : public UDP {
4545

4646
public:
4747
WiFiUDP(); // Constructor
48+
~WiFiUDP();
4849
virtual uint8_t begin(uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
4950
// virtual uint8_t beginMulticast(IPAddress, uint16_t); // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 if there are no sockets available to use
5051
virtual void stop(); // Finish with the UDP socket

0 commit comments

Comments
 (0)