mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-16 12:02:11 +02:00
mdns: resolve memory leak when txt record received multiple times
* Original commit: espressif/esp-idf@a6b2b73f03
This commit is contained in:
committed by
suren-gabrielyan-espressif
parent
2763bcdb8d
commit
b4e57424f9
@ -2769,10 +2769,6 @@ void mdns_parse_packet(mdns_rx_packet_t * packet)
|
|||||||
if (search_result) {
|
if (search_result) {
|
||||||
mdns_txt_item_t * txt = NULL;
|
mdns_txt_item_t * txt = NULL;
|
||||||
size_t txt_count = 0;
|
size_t txt_count = 0;
|
||||||
_mdns_result_txt_create(data_ptr, data_len, &txt, &txt_count);
|
|
||||||
if (!txt_count) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
mdns_result_t * result = NULL;
|
mdns_result_t * result = NULL;
|
||||||
if (search_result->type == MDNS_TYPE_PTR) {
|
if (search_result->type == MDNS_TYPE_PTR) {
|
||||||
@ -2792,8 +2788,11 @@ void mdns_parse_packet(mdns_rx_packet_t * packet)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!result->txt) {
|
if (!result->txt) {
|
||||||
result->txt = txt;
|
_mdns_result_txt_create(data_ptr, data_len, &txt, &txt_count);
|
||||||
result->txt_count = txt_count;
|
if (txt_count) {
|
||||||
|
result->txt = txt;
|
||||||
|
result->txt_count = txt_count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_mdns_search_result_add_txt(search_result, txt, txt_count, packet->tcpip_if, packet->ip_protocol);
|
_mdns_search_result_add_txt(search_result, txt, txt_count, packet->tcpip_if, packet->ip_protocol);
|
||||||
@ -3305,7 +3304,7 @@ static void _mdns_search_result_add_txt(mdns_search_once_t * search, mdns_txt_it
|
|||||||
while (r) {
|
while (r) {
|
||||||
if (r->tcpip_if == tcpip_if && r->ip_protocol == ip_protocol) {
|
if (r->tcpip_if == tcpip_if && r->ip_protocol == ip_protocol) {
|
||||||
if (r->txt) {
|
if (r->txt) {
|
||||||
return;
|
goto free_txt;
|
||||||
}
|
}
|
||||||
r->txt = txt;
|
r->txt = txt;
|
||||||
r->txt_count = txt_count;
|
r->txt_count = txt_count;
|
||||||
@ -3316,12 +3315,7 @@ static void _mdns_search_result_add_txt(mdns_search_once_t * search, mdns_txt_it
|
|||||||
if (!search->max_results || search->num_results < search->max_results) {
|
if (!search->max_results || search->num_results < search->max_results) {
|
||||||
r = (mdns_result_t *)malloc(sizeof(mdns_result_t));
|
r = (mdns_result_t *)malloc(sizeof(mdns_result_t));
|
||||||
if (!r) {
|
if (!r) {
|
||||||
for (i=0; i<txt_count; i++) {
|
goto free_txt;
|
||||||
free((char *)(txt[i].key));
|
|
||||||
free((char *)(txt[i].value));
|
|
||||||
}
|
|
||||||
free(txt);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(r, 0 , sizeof(mdns_result_t));
|
memset(r, 0 , sizeof(mdns_result_t));
|
||||||
@ -3333,6 +3327,14 @@ static void _mdns_search_result_add_txt(mdns_search_once_t * search, mdns_txt_it
|
|||||||
search->result = r;
|
search->result = r;
|
||||||
search->num_results++;
|
search->num_results++;
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
|
||||||
|
free_txt:
|
||||||
|
for (i=0; i<txt_count; i++) {
|
||||||
|
free((char *)(txt[i].key));
|
||||||
|
free((char *)(txt[i].value));
|
||||||
|
}
|
||||||
|
free(txt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user