From b865e72aec96166c90d4580cdb94050bd53e6a75 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Thu, 14 Feb 2019 16:39:11 +0100 Subject: [PATCH 1/5] mdns: fix memory leak when query for service receives multiple ptr entries for one instance fixes redmine issue 27300 --- components/mdns/mdns.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/components/mdns/mdns.c b/components/mdns/mdns.c index 1626ffaeb80e..1bce6db43fe6 100644 --- a/components/mdns/mdns.c +++ b/components/mdns/mdns.c @@ -2741,8 +2741,10 @@ void mdns_parse_packet(mdns_rx_packet_t * packet) if (search_result) { if (search_result->type == MDNS_TYPE_PTR) { - result->port = port; - result->hostname = strdup(name->host); + if (!result->hostname) { // assign host/port for this entry only if not previously set + result->port = port; + result->hostname = strdup(name->host); + } } else { _mdns_search_result_add_srv(search_result, name->host, port, packet->tcpip_if, packet->ip_protocol); } From 78116afa01a2a04d71adf9ebd9e92e2ca06d3f53 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Fri, 15 Feb 2019 13:23:21 +0100 Subject: [PATCH 2/5] mdns: fix possible crash when mdns_free called while action queue not empty --- components/mdns/mdns.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/mdns/mdns.c b/components/mdns/mdns.c index 1bce6db43fe6..cf16ae65617e 100644 --- a/components/mdns/mdns.c +++ b/components/mdns/mdns.c @@ -4017,8 +4017,6 @@ static esp_err_t _mdns_service_task_stop() MDNS_SERVICE_LOCK(); _mdns_stop_timer(); MDNS_SERVICE_UNLOCK(); - vSemaphoreDelete(_mdns_service_semaphore); - _mdns_service_semaphore = NULL; if (_mdns_service_task_handle) { mdns_action_t action; mdns_action_t * a = &action; @@ -4031,6 +4029,8 @@ static esp_err_t _mdns_service_task_stop() vTaskDelay(10 / portTICK_PERIOD_MS); } } + vSemaphoreDelete(_mdns_service_semaphore); + _mdns_service_semaphore = NULL; return ESP_OK; } From bb2eb9adebc5f8c46f004da4523d83c527a3925c Mon Sep 17 00:00:00 2001 From: David Cermak Date: Fri, 15 Feb 2019 13:46:51 +0100 Subject: [PATCH 3/5] mdns: fix malfuctional query_txt when running a query for a single txt, result entries were not created and attached to result structure. this issue was introduced when fixing memory leak in txt structure, which worked correctly for PTR queries, but caused trouble for TXT query. --- components/mdns/mdns.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/mdns/mdns.c b/components/mdns/mdns.c index cf16ae65617e..84d578b3c26d 100644 --- a/components/mdns/mdns.c +++ b/components/mdns/mdns.c @@ -2831,7 +2831,10 @@ void mdns_parse_packet(mdns_rx_packet_t * packet) } } } else { - _mdns_search_result_add_txt(search_result, txt, txt_count, packet->tcpip_if, packet->ip_protocol); + _mdns_result_txt_create(data_ptr, data_len, &txt, &txt_count); + if (txt_count) { + _mdns_search_result_add_txt(search_result, txt, txt_count, packet->tcpip_if, packet->ip_protocol); + } } } else if (ours) { if (parsed_packet->questions && !parsed_packet->probe) { From 3802fddefb3654b8eadd4d922c0849612aab1874 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Fri, 15 Feb 2019 15:54:18 +0100 Subject: [PATCH 4/5] mdns example: fix print result for IPv6 addresses --- examples/protocols/mdns/main/mdns_example_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/protocols/mdns/main/mdns_example_main.c b/examples/protocols/mdns/main/mdns_example_main.c index fb805545aba8..bf8dd879cc59 100644 --- a/examples/protocols/mdns/main/mdns_example_main.c +++ b/examples/protocols/mdns/main/mdns_example_main.c @@ -143,7 +143,7 @@ static void mdns_print_results(mdns_result_t * results){ } a = r->addr; while(a){ - if(a->addr.type == MDNS_IP_PROTOCOL_V6){ + if(a->addr.type == IPADDR_TYPE_V6){ printf(" AAAA: " IPV6STR "\n", IPV62STR(a->addr.u_addr.ip6)); } else { printf(" A : " IPSTR "\n", IP2STR(&(a->addr.u_addr.ip4))); From 113e8295528b6a6455c585b16d5dfcad8bfc3ac4 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Fri, 15 Feb 2019 15:59:11 +0100 Subject: [PATCH 5/5] mdns: fix memory leak in pbuf if tcpipadapter failed to get netif --- components/mdns/mdns_networking.c | 1 + 1 file changed, 1 insertion(+) diff --git a/components/mdns/mdns_networking.c b/components/mdns/mdns_networking.c index 981b9d825266..bb3400f0afb3 100644 --- a/components/mdns/mdns_networking.c +++ b/components/mdns/mdns_networking.c @@ -301,6 +301,7 @@ static err_t _mdns_udp_pcb_write_api(struct tcpip_api_call_data *api_call_msg) mdns_pcb_t * _pcb = &_mdns_server->interfaces[msg->tcpip_if].pcbs[msg->ip_protocol]; esp_err_t err = tcpip_adapter_get_netif(msg->tcpip_if, &nif); if (err) { + pbuf_free(msg->pbt); msg->err = err; return err; }