Skip to content

Commit

Permalink
Fix resource leaks in UDP library
Browse files Browse the repository at this point in the history
Reference counts were not incremented after creation of UdpContext, so pbufs and pcbs were not freed.
  • Loading branch information
igrr committed Apr 13, 2015
1 parent 7b70acf commit ed76e56
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit ed76e56

Please sign in to comment.