Skip to content

Commit da88852

Browse files
committed
Fix resource leaks in UDP library
Reference counts were not incremented after creation of UdpContext, so pbufs and pcbs were not freed.
1 parent 6b593a7 commit da88852

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Diff for: libraries/ESP8266WiFi/src/WiFiUdp.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ uint8_t WiFiUDP::begin(uint16_t port)
6868
{
6969
if (_ctx) {
7070
_ctx->unref();
71+
_ctx = 0;
7172
}
7273

7374
_ctx = new UdpContext;
75+
_ctx->ref();
7476
ip_addr_t addr;
7577
addr.addr = INADDR_ANY;
7678
return (_ctx->listen(addr, port)) ? 1 : 0;
@@ -93,7 +95,7 @@ uint8_t WiFiUDP::beginMulticast(IPAddress interfaceAddr, IPAddress multicast, ui
9395
}
9496

9597
_ctx = new UdpContext;
96-
98+
_ctx->ref();
9799
if (!_ctx->listen(*IP_ADDR_ANY, port)) {
98100
return 0;
99101
}
@@ -133,8 +135,10 @@ int WiFiUDP::beginPacket(IPAddress ip, uint16_t port)
133135
ip_addr_t addr;
134136
addr.addr = ip;
135137

136-
if (!_ctx)
138+
if (!_ctx) {
137139
_ctx = new UdpContext;
140+
_ctx->ref();
141+
}
138142
return (_ctx->connect(addr, port)) ? 1 : 0;
139143
}
140144

0 commit comments

Comments
 (0)