From 5fb665dbaf57b68656b10ff97411709d995ee558 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Mon, 23 Jul 2018 16:15:02 +1000 Subject: [PATCH] udp_multicast example: Fix memory leak from getaddrinfo() calls Closes https://github.com/espressif/esp-idf/issues/2201 --- .../protocols/udp_multicast/main/udp_multicast_example_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/protocols/udp_multicast/main/udp_multicast_example_main.c b/examples/protocols/udp_multicast/main/udp_multicast_example_main.c index 18678d0ea..a8efd1f08 100644 --- a/examples/protocols/udp_multicast/main/udp_multicast_example_main.c +++ b/examples/protocols/udp_multicast/main/udp_multicast_example_main.c @@ -506,6 +506,7 @@ static void mcast_example_task(void *pvParameters) ESP_LOGI(TAG, "Sending to IPV6 (V4 mapped) multicast address %s (%s)...", addrbuf, CONFIG_EXAMPLE_MULTICAST_IPV4_ADDR); #endif err = sendto(sock, sendbuf, len, 0, res->ai_addr, res->ai_addrlen); + freeaddrinfo(res); if (err < 0) { ESP_LOGE(TAG, "IPV4 sendto failed. errno: %d", errno); break; @@ -523,12 +524,12 @@ static void mcast_example_task(void *pvParameters) break; } - struct sockaddr_in6 *s6addr = (struct sockaddr_in6 *)res->ai_addr; s6addr->sin6_port = htons(UDP_PORT); inet6_ntoa_r(s6addr->sin6_addr, addrbuf, sizeof(addrbuf)-1); ESP_LOGI(TAG, "Sending to IPV6 multicast address %s...", addrbuf); err = sendto(sock, sendbuf, len, 0, res->ai_addr, res->ai_addrlen); + freeaddrinfo(res); if (err < 0) { ESP_LOGE(TAG, "IPV6 sendto failed. errno: %d", errno); break;