diff --git a/libraries/AsyncUDP/src/AsyncUDP.cpp b/libraries/AsyncUDP/src/AsyncUDP.cpp index 762529b9e0f..66d486c0231 100644 --- a/libraries/AsyncUDP/src/AsyncUDP.cpp +++ b/libraries/AsyncUDP/src/AsyncUDP.cpp @@ -324,6 +324,22 @@ AsyncUDPPacket::AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *raddr, } } +AsyncUDPPacket::AsyncUDPPacket(const AsyncUDPPacket &packet) + : _udp(packet._udp), + _pb(packet._pb), + _if(packet._if), + _localIp(packet._localIp), + _localPort(packet._localPort), + _remoteIp(packet._remoteIp), + _remotePort(packet._remotePort), + _data(packet._data), + _len(packet._len), + _index(packet._index) +{ + memcpy(_remoteMac, packet._remoteMac, sizeof(_remoteMac)); + pbuf_ref(_pb); +} + AsyncUDPPacket::~AsyncUDPPacket() { pbuf_free(_pb); @@ -682,9 +698,8 @@ void AsyncUDP::_recv(udp_pcb *upcb, pbuf *pb, const ip_addr_t *addr, uint16_t po if(_handler) { AsyncUDPPacket packet(this, this_pb, addr, port, netif); _handler(packet); - } else { - pbuf_free(this_pb); } + pbuf_free(this_pb); } } diff --git a/libraries/AsyncUDP/src/AsyncUDP.h b/libraries/AsyncUDP/src/AsyncUDP.h index 2ac48a69684..548b1527da2 100644 --- a/libraries/AsyncUDP/src/AsyncUDP.h +++ b/libraries/AsyncUDP/src/AsyncUDP.h @@ -59,6 +59,7 @@ class AsyncUDPPacket : public Stream size_t _index; public: AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *addr, uint16_t port, struct netif * netif); + AsyncUDPPacket(const AsyncUDPPacket &packet); virtual ~AsyncUDPPacket(); uint8_t * data();