Skip to content

Commit 8134a42

Browse files
committed
Fix leak of memory and possible crashes in AsyncUDP
1 parent f13ff65 commit 8134a42

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

libraries/AsyncUDP/src/AsyncUDP.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,16 @@ void AsyncUDPMessage::flush()
277277
_index = 0;
278278
}
279279

280+
AsyncUDPPacket::AsyncUDPPacket(AsyncUDPPacket &packet){
281+
_udp = packet._udp;
282+
_pb = packet._pb;
283+
_if = packet._if;
284+
_data = packet._data;
285+
_len = packet._len;
286+
_index = 0;
287+
288+
pbuf_ref(_pb);
289+
}
280290

281291
AsyncUDPPacket::AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *raddr, uint16_t rport, struct netif * ntif)
282292
{
@@ -683,9 +693,8 @@ void AsyncUDP::_recv(udp_pcb *upcb, pbuf *pb, const ip_addr_t *addr, uint16_t po
683693
if(_handler) {
684694
AsyncUDPPacket packet(this, this_pb, addr, port, netif);
685695
_handler(packet);
686-
} else {
687-
pbuf_free(this_pb);
688696
}
697+
pbuf_free(this_pb);
689698
}
690699
}
691700

libraries/AsyncUDP/src/AsyncUDP.h

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class AsyncUDPPacket : public Stream
5858
size_t _len;
5959
size_t _index;
6060
public:
61+
AsyncUDPPacket(AsyncUDPPacket &packet);
6162
AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *addr, uint16_t port, struct netif * netif);
6263
virtual ~AsyncUDPPacket();
6364

0 commit comments

Comments
 (0)