1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-16 11:21:18 +03:00

Fix resource leaks in UDP library

Reference counts were not incremented after creation of UdpContext, so pbufs and pcbs were not freed.
This commit is contained in:
Ivan Grokhotkov
2015-04-14 01:34:52 +08:00
parent 7b70acf337
commit ed76e56468

View File

@ -68,9 +68,11 @@ uint8_t WiFiUDP::begin(uint16_t port)
{
if (_ctx) {
_ctx->unref();
_ctx = 0;
}
_ctx = new UdpContext;
_ctx->ref();
ip_addr_t addr;
addr.addr = INADDR_ANY;
return (_ctx->listen(addr, port)) ? 1 : 0;
@ -93,7 +95,7 @@ uint8_t WiFiUDP::beginMulticast(IPAddress interfaceAddr, IPAddress multicast, ui
}
_ctx = new UdpContext;
_ctx->ref();
if (!_ctx->listen(*IP_ADDR_ANY, port)) {
return 0;
}
@ -133,8 +135,10 @@ int WiFiUDP::beginPacket(IPAddress ip, uint16_t port)
ip_addr_t addr;
addr.addr = ip;
if (!_ctx)
if (!_ctx) {
_ctx = new UdpContext;
_ctx->ref();
}
return (_ctx->connect(addr, port)) ? 1 : 0;
}