From da88852693da826808b9682489f5ae8e1ed0a533 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 14 Apr 2015 01:34:52 +0800 Subject: [PATCH] Fix resource leaks in UDP library Reference counts were not incremented after creation of UdpContext, so pbufs and pcbs were not freed. --- libraries/ESP8266WiFi/src/WiFiUdp.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libraries/ESP8266WiFi/src/WiFiUdp.cpp b/libraries/ESP8266WiFi/src/WiFiUdp.cpp index 96928f24a..bf7e6c881 100644 --- a/libraries/ESP8266WiFi/src/WiFiUdp.cpp +++ b/libraries/ESP8266WiFi/src/WiFiUdp.cpp @@ -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; }